Discussion:
FVWM: building dynamic menus for fvwmbuttons
James Griffin
2013-08-25 11:41:45 UTC
Permalink
Hi

I have used an example for creating a dynamic menu to view pictures,
found on the fvwm site to create a documents menu.

The problem I have is -- in both examples really -- the files in these
directories are likely to different types. So, using the pictures example
on the fvwm site, it shows how to create the menu for files of .jpg type.

I would like to extend it show all the files, i.e. not just
jpg files, but to use a different program to view different file types.

to make this clearer, here is the function is question for the pictures
menu shown on the fvwm site:

AddToMenu JpgMenu Pictures title
+ MissingSubmenuFunction FuncFvwmMenuDirectory
+ DynamicPopupAction Function MakeJpgMenu

AddToFunc MakeJpgMenu
+ I DestroyMenu recreate JpgMenu
+ I AddToMenu JpgMenu Pictures Title
+ I PipeRead 'for i in $HOME/pictures/*.jpg; \
do echo AddToMenu JpgMenu "`basename $i`" Exec xv $i; done'

As it happens, xv can open all of the image types i'm likely to ever have
in that directory, so I can alter it to list all files by replacing
'*.jpg' with '*.*'

following this example, with my document directory, I will most likely
have pdf, doc, docx (OpenOffice stuff), text files, ... etc. So for each
type I will need a different program to be executed in order to view
and/or edit them.

How can I extend the function to map different file types to their
respective programs? Naturally, xpdf for pdf's; OpenOffice for .doc[x];
emacs or vi for text files.

I "think" it would need a shell case statement, perhaps? Although i'm not
certain about that and also not confident enough to write it.

Would someone mind showing me how I could do this? Perhaps to provide an
example?

Many thanks.

Jamie.
--
James Griffin: jmz at kontrol.kode5.net

A4B9 E875 A18C 6E11 F46D B788 BEE6 1251 1D31 DC38
Dan Espen
2013-08-25 23:04:38 UTC
Permalink
Post by James Griffin
Hi
I have used an example for creating a dynamic menu to view pictures,
found on the fvwm site to create a documents menu.
The problem I have is -- in both examples really -- the files in these
directories are likely to different types. So, using the pictures example
on the fvwm site, it shows how to create the menu for files of .jpg type.
I would like to extend it show all the files, i.e. not just
jpg files, but to use a different program to view different file types.
to make this clearer, here is the function is question for the pictures
AddToMenu JpgMenu Pictures title
+ MissingSubmenuFunction FuncFvwmMenuDirectory
+ DynamicPopupAction Function MakeJpgMenu
AddToFunc MakeJpgMenu
+ I DestroyMenu recreate JpgMenu
+ I AddToMenu JpgMenu Pictures Title
+ I PipeRead 'for i in $HOME/pictures/*.jpg; \
do echo AddToMenu JpgMenu "`basename $i`" Exec xv $i; done'
As it happens, xv can open all of the image types i'm likely to ever have
in that directory, so I can alter it to list all files by replacing
'*.jpg' with '*.*'
I "think" it would need a shell case statement, perhaps? Although i'm not
certain about that and also not confident enough to write it.
Would someone mind showing me how I could do this? Perhaps to provide an
example?
Try replacing '*.jpg' with just '*'.

*.* is from Windows .BAT files.

When referring to $i, always include quotes like this:

do echo AddToMenu JpgMenu "`basename "$i"`" Exec xv "$i"; done'

(You need the quotes to handle file names with spaces.)

Instead of 'Exec xv' do:

Exec exec my-handle-file.

Where "my-handle-file" is a shell you write that figures out what
program to execute.

In my-handle-file figure out what to execute based on $1:

case "$1" in
*.jpg) exec xv $1;;
*.doc) exec ooffice $1;;
*) echo "say what";;
esac
--
Dan Espen
Dan Espen
2013-08-25 23:12:19 UTC
Permalink
Post by Dan Espen
Post by James Griffin
Hi
I have used an example for creating a dynamic menu to view pictures,
found on the fvwm site to create a documents menu.
The problem I have is -- in both examples really -- the files in these
directories are likely to different types. So, using the pictures example
on the fvwm site, it shows how to create the menu for files of .jpg type.
I would like to extend it show all the files, i.e. not just
jpg files, but to use a different program to view different file types.
to make this clearer, here is the function is question for the pictures
AddToMenu JpgMenu Pictures title
+ MissingSubmenuFunction FuncFvwmMenuDirectory
+ DynamicPopupAction Function MakeJpgMenu
AddToFunc MakeJpgMenu
+ I DestroyMenu recreate JpgMenu
+ I AddToMenu JpgMenu Pictures Title
+ I PipeRead 'for i in $HOME/pictures/*.jpg; \
do echo AddToMenu JpgMenu "`basename $i`" Exec xv $i; done'
As it happens, xv can open all of the image types i'm likely to ever have
in that directory, so I can alter it to list all files by replacing
'*.jpg' with '*.*'
I "think" it would need a shell case statement, perhaps? Although i'm not
certain about that and also not confident enough to write it.
Would someone mind showing me how I could do this? Perhaps to provide an
example?
Try replacing '*.jpg' with just '*'.
*.* is from Windows .BAT files.
do echo AddToMenu JpgMenu "`basename "$i"`" Exec xv "$i"; done'
(You need the quotes to handle file names with spaces.)
Exec exec my-handle-file.
Where "my-handle-file" is a shell you write that figures out what
program to execute.
case "$1" in
*.jpg) exec xv $1;;
*.doc) exec ooffice $1;;
*) echo "say what";;
esac
(Oops, of course quotes around all the references to $1,
and my-handle-file must be a shell with execute permission
and in your $PATH.)
--
Dan Espen
James Griffin
2013-08-26 09:38:52 UTC
Permalink
Post by Dan Espen
Post by Dan Espen
Try replacing '*.jpg' with just '*'.
*.* is from Windows .BAT files.
do echo AddToMenu JpgMenu "`basename "$i"`" Exec xv "$i"; done'
(You need the quotes to handle file names with spaces.)
Exec exec my-handle-file.
Where "my-handle-file" is a shell you write that figures out what
program to execute.
case "$1" in
*.jpg) exec xv $1;;
*.doc) exec ooffice $1;;
*) echo "say what";;
esac
(Oops, of course quotes around all the references to $1,
and my-handle-file must be a shell with execute permission
and in your $PATH.)
Hi Dan, thanks very much for explaining that. It makes sense to me now. I
will try out some new menus using this approach.

It's very coold being able to do stuff like this. I really need to extend
my shell skills so I can do more cools things.

Cheers, Jamie.
--
James Griffin: jmz at kontrol.kode5.net

[A4B9 E875 A18C 6E11 F46D B788 BEE6 1251 1D31 DC38]
Loading...