Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

4 Answers 4

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

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

http://wiki.matusov.sk/howto/gnome-menu-edit

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

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.