Saturday, February 21, 2009

Gnome Application Menus

I really don't like the way the Gnome applications menu works. Oh... I know KDE is better, but its what Red Hat uses, so I got to deal with it. The issue is that in Red Hat and Fedora, the menu is locked down to prevent you from adding new entries. Why, you ask... Good question:

To add menu items, we first have to be root. Next we go to a directory that holds a group of files that describe the menu entries. Lastly, we hack a new entry-- which is the tricky part.
$ su -
# cd /usr/share/applications
# ls
The files labeled .desktop are descriptor files with a proprietary format. The easiest thing is to copy one that is already there. As an example we'll add /usr/bin/xclock using gnome-about.desktop as our template. Unfortunately, gnome-about.desktop has a bunch of garbage in it for internationalization. Who'd want that?
# grep -v "[-=]GN\|.\[ gnome-about.desktop > ourName.desktop
vi ourName.desktop
We need to change some things, most of which should be obvious.
[Desktop Entry]
Comment=Menu test using Xclock
Save the file. Click the applications menu and select "Other". (If you don't see other, right click on "Applications", select "Edit Menus", check the box next to "Other". Click "Close".

We're not done, but do notice the icon. In the file we did not specify a path, so it looks under either /usr/share/pixmaps or /usr/share/icons. Edit the file again and make this change:
Save the file, and check the menu item again. The icon should have changed.

Now lets get it into a menu group other than "Other". This is the hacky part. Edit the file, add the following:
Look through the menu again. In Red Hat and Fedora, it the item should have moved to the "Accessories" folder. How did it end up in "Accessories" when we told it to go to "Utilities". Unfortunately, the names we see are not the name of the groups. To see the mapping of groups to names, try this:
grep "Name=" /usr/share/desktop-directories/* | \
grep -iv more | cut -d/ -f5 | sort -t: -k2 | sed "s~\..*:Name~~"
Use the name on the left, to get it in the group on the right.

See, I told you this was a nasty hack.

No comments:

Post a Comment