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 -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?
# cd /usr/share/applications
# ls
# grep -v "[-=]GN\|.\[ gnome-about.desktop > ourName.desktopWe need to change some things, most of which should be obvious.
vi ourName.desktop
[Desktop Entry]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".
Encoding=UTF-8
Name=Xclock
Comment=Menu test using Xclock
Exec=/usr/bin/xclock
Icon=gnome-xterm.png
Terminal=false
Type=Application
StartupNotify=true
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:
Icon=/usr/share/icons/gnome/32x32/actions/add.pngSave 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:
Categories=Utility;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/* | \Use the name on the left, to get it in the group on the right.
grep -iv more | cut -d/ -f5 | sort -t: -k2 | sed "s~\..*:Name~~"
See, I told you this was a nasty hack.
No comments:
Post a Comment