How can I add menu items to the Gnome "Applications" menu from the command line?

Here's a link for a shell script which will create entries in GNOME's menu

Snippet of the post:

I have seen this question asked frequently on the Ubuntu forums. This page will teach you how. You as a user can make your own menu entry by right clicking on the menu icon in the upper left corner and selecting Edit Menus. This bring up a GUI an you can select which section to install the menu item in. We want to create one via a shell script.

All menu items are stored in the /usr/share/applications folder. In that folder there will be a .desktop file for each menu entry. Lets get into those .desktop files shall we?

Here is an example of the contents of a .desktop file: What the following code does is make a menu entry called Kompozer in the Programming section of the Gnome menu.


It should be noted that the alacarte doesn't put the items you add in /usr/share/applications. It adds them to your home directory. So if you're not wanting to create entries for every user, just the current user, you'll need to make the below changes.

Below is a test entry, added via alacarte, and the resulting files that were created.

(1) The local applications.menu file is updated. Note the <Filename> entry.

# cat /home/user/.config/menus/applications.menu 
<!DOCTYPE Menu
 PUBLIC '-//freedesktop//DTD Menu 1.0//EN'
 'http://standards.freedesktop.org/menu-spec/menu-1.0.dtd'>
<Menu>
<Name>Applications</Name>
<MergeFile type="parent">/etc/xdg/menus/applications.menu</MergeFile>
<Menu>
<Name>Internet</Name>
<Include>
<Filename>alacarte-made.desktop</Filename>
</Include>
</Menu>
</Menu>

(2) The alacarte-made.desktop file is created in ~/.local/share/applications.

# ls -ltr ~/.local/share/applications/
-rw------- 1 user user  495 2010-04-14 15:48 Nokia-QtCreator.desktop
-rw------- 1 user user  403 2010-04-14 15:48 defaults.list
-rw-r--r-- 1 user user  134 2010-12-20 10:33 userapp-gvim-JYONNV.desktop
-rw-r--r-- 1 user user  321 2010-12-20 10:33 mimeinfo.cache
-rw-r--r-- 1 user user  165 2010-12-20 10:33 mimeapps.list
drwx------ 9 user user 4096 2011-05-26 15:34 ..
-rw------- 1 user user  108 2011-05-26 15:34 installjammer-program.desktop
-rw------- 1 user user  182 2011-05-26 15:34 installjammer-help.desktop
-rw------- 1 user user  201 2011-05-26 15:34 installjammer-userguide.desktop
-rw------- 1 user user  114 2011-05-26 15:34 installjammer-uninstall.desktop
-rwxr-xr-x 1 user user  202 2011-06-10 09:27 alacarte-made.desktop
-rw-r--r-- 1 user user  202 2011-06-10 09:28 alacarte-made.desktop.undo-0
drwxr-xr-x 2 user user 4096 2011-06-10 09:28 .

(3) If you look at the contents of alacarte-made.desktop you see the "test" entry that was added to my menu.

# cat ~/.local/share/applications/alacarte-made.desktop
#!/usr/bin/env xdg-open

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=gnome-panel-launcher
Name[en_US]=test
Exec=secretsync
Name=test
Icon=gnome-panel-launcher

I'm not certain the best way to modify the applications.menu file in 1 above. It's obviously a specifically formatted file, and I don't know if there is a utility that could be used to make an entry from a script or command-line.