Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Ubuntu 9.10, and I'd like to automate the addition of some menu items the Ubuntu "Applications" menu.

I know that I can use alacarte to make one-off additions, but I'm looking to automate (either via Perl or Bash) the addition of many menu items to this menu.

Any ideas?

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer

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 file is updated. Note the <Filename> entry.

# cat /home/user/.config/menus/ 
 PUBLIC '-//freedesktop//DTD Menu 1.0//EN'
<MergeFile type="parent">/etc/xdg/menus/</MergeFile>

(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]

I'm not certain the best way to modify the 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.

share|improve this answer

In addition to the link Sathya provided, this also shows how to automate adding additional menus to the Applications menu:

share|improve this answer

Some of the other answers here have incorrect paths (at least, they do not exist on my Ubuntu 10.10 system) or only address system-level menus. Gnome user-level menus are stored in your $XDG_CONFIG_HOME/menus directory (by default ~/.config/menus/) and $XDG_DATA_HOME/applications directory (by default ~/.local/share/applications). You can manually edit these files. See this Ubunto Forums thread for some details; specifically the Desktop Menu Specification tells more about the files and their format.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .