On Fri, 19 Jun 2009 06:13:07 +0300
Jason Brower <[email protected]> wrote:

> I think that's a nifty idea, is there a way to pull the icons too?
> Regards,
> Jason
> 
> 
> On Thu, 2009-06-18 at 10:01 -0700, John H. Robinson, IV wrote:
> > sean wrote:
> > > Any chance an upcoming release could include the tools to auto generate 
> > > an application menu if desired?
> > > 
> > > Perhaps a button in the preferences area?
> > 
> > Where would it get that information from?
> > 
> > I can think of a few ideas - the package manager similar to Debian's
> > menu system; search through $PATH; drag and drop from a file browser.
> > 
> > -- 
> > John H. Robinson, IV          [email protected]
> >                                                                  http  ((((
> > WARNING: I cannot be held responsible for the above,         sbih.org ( )(:[
> > as apparently my cats have learned how to type.          spiders.html  ((((
> > 
> > 
> 
> 
> -- 
> To unsubscribe, send mail to [email protected].

In the sources there is util/wkdemenu.pl which was for generating menus from 
kde *.lnk files which were nearly the same as desktop files. It could be 
altered to do a better job with desktop files. My perl skills are nil, so I had 
written a similar tool in bash:

$ cat wm-gen-desktop-menu
#!/bin/bash
# /usr/bin/wm-gen-desktop-menu
# Gilbert Ashley <[email protected]>

# this script can be used to generate a WindowMaker submenu
# of installed programs which have a *.desktop file
# the script expects a directory path as an argument.

# In order to use this script, you need to first create a directory structure 
which
# holds the menu categories as subdirectories with the *.desktop files in them.
# To do that, first run the script /usr/bin/wm-update-desktop-menus
# By default, this will create the menu subdirectories in ~/GNUstep/DesktopMenus
# or you can use another directory by passing the directory path as an argument 
to the script

# Then, you can add a line this to your WindowMaker WMRootMenu file:
# ("Desktop Applications", OPEN_MENU, "|| /usr/bin/wm-gen-desktop-menu 
~/GNUstep/DesktopMenus"),
# Or you can use the WPrefs application to add a 'Generated Submenu' with this 
command:
# /usr/bin/wm-gen-desktop-menu ~/GNUstep/DesktopMenus

if [ $1 ] ; then
        DESKTOP_FILES_PATH=$1
else
        DESKTOP_FILES_PATH=~/GNUstep/DesktopMenus
fi

cd $DESKTOP_FILES_PATH
echo \"Desktop Menu\" MENU
for DIR in $(find * -type d) ; do
        echo \"$DIR\" MENU
        #for DSK in $(ls -1 $DIR ) ; do
        for DSK in $DIR/* ; do
                NAME=$(grep '^Name=' $DSK |cut -f2 -d=)
                COMMAND=$(grep '^Exec=' $DSK |cut -f2 -d=)
                COMMAND=${COMMAND/\%F/\"\...@\"}
                COMMAND=${COMMAND/\%f/\"\$\1\"}
                COMMAND=${COMMAND/\%U/\"\...@\"}
                COMMAND=${COMMAND/\%u/\"\$\1\"}
                #echo ${DSK/#*\/} $NAME
                echo "  "\"$NAME\" EXEC "$COMMAND"
                DSK=
                NAME=
                COMMAND=
        done
        echo \"$DIR\" END
        DIR=
done
echo \"Desktop Menu\" END

I use that in combination with this:

$ cat wm-update-desktop-menus
#!/bin/bash
# This script will generate a directory and symlink structure which
# can be used with the wm-gen-desktop-menu script to create a wmaker
# menu on the fly for installed progams with a *.desktop file
# In order to keep this database up-to-date, this script should be run
# after installing new software, or it can be included in your startup

if [ $1 ] ; then
        DESKTOP_FILES_PATH=$1
else
        DESKTOP_FILES_PATH=~/GNUstep/DesktopMenus
fi

# if you already have xdg menus, then you probably have desktop files here:
if [ -d ~/.local/share/applications ] ; then
 DESKTOP_APPS=~/.local/share/applications
else
 # otherwise, use the ones installed in the system directory
 DESKTOP_APPS=/usr/share/applications
fi

for DSK in $(ls -1 $DESKTOP_APPS/*.desktop) ; do
        CATEGORIES=$(grep Categories $DSK |cut -f2 -d'=')
        OLDIFS=$IFS
        IFS=';'
        for CATEGORY in $CATEGORIES ; do
                  if ! [ -d $DESKTOP_FILES_PATH/$CATEGORY ] ; then
                        mkdir -p $DESKTOP_FILES_PATH/$CATEGORY
                  fi
                  if ! [ -e $DESKTOP_FILES_PATH/$CATEGORY/$(basename $DSK) ] ; 
then
                        # if you want to save space you can create links to the 
desktop files
                        #ln -sf $DSK $DESKTOP_FILES_PATH/$CATEGORY/$(basename 
$DSK)
                        # It's probably better to copy the files so they can be 
altered by the user
                        cp $DSK $DESKTOP_FILES_PATH/$CATEGORY/$(basename $DSK)
                  fi
        done
        IFS=$OLDIFS
done

I actually started with just directly generating the menu from the system 
installed desktop files. But then I wanted to make it more flexible so that 
each user could add/delete desktop files from their own database. This is still 
not really desktop.org-compliant. These bash scripts are pretty slow compared 
to perl.

I use wmaker with ROX-Filer, so I also wrote a utility which generates a 
dynamic menu of ROX AppDir application directories:

$ cat wm-gen-appdir-menu
#!/bin/bash
# /usr/bin/wm-build-appdir-menu
# Gilbert Ashley <[email protected]>

# this script can be used to generate a sub-menu of ROX AppDirs
# for the WindowMaker menu. It expects a directory name as input.
# An example  menu entry for the plmenu (perl menu) looks like this:
# (AppDirs, OPEN_MENU, "|| /usr/bin/wm-build-appdir-menu /usr/apps"),
# Or, you can use the WPrefs application to add a 'Generated Submenu'
# with the command: /usr/bin/wm-build-appdir-menu /usr/apps

APPDIRS="$@"
if [ "$APPDIRS" = "" ] ; then
        exit
fi
for DIR in $APPDIRS ; do
        echo "\"AppDirs\" MENU"
        for AppDir in $(ls -1 $DIR) ; do
                echo $AppDir EXEC $DIR/$AppDir/AppRun
        done
        echo "\"AppDirs\" END"
done

For those to work you need an entries like these in your menu:
For the first example:
  ("Desktop Applications", OPEN_MENU, "|| /usr/bin/wm-gen-desktop-menu"),
For the second example:
  (AppDirs, OPEN_MENU, "|| /usr/bin/wm-gen-appdir-menu /usr/apps"),

Another example of simply creating a menu from the contents of a 
directory(which could be links to desired apps):
("Directory Contents", OPEN_MENU, "/usr/apps"),

Gilbert Ashley


-- 
To unsubscribe, send mail to [email protected].

Reply via email to