How To Add an Item To The GNOME Menu For All Users

July 30, 2009 by Linerd
Filed under: HowTo, Ubuntu, gnome, linux 

I've shown previously how to add an item to Ubuntu's (or any Gnome desktop) menu, but that post only showed how to edit the menu for a single user. In this post I'll show how to add an item to the menu so it shows up for every user on the system. I'm going to add a special icon to launch a terminal window from the Applications->Accessories menu in Ubuntu. You can find more info at the GNOME Documentation Library.

Create a Desktop Launcher

Right click on the Desktop and select Create Launcher. Enter a name, I'll call mine Tux Term. Enter the command, in my case it's gnome-terminal.

Create a Launcher for Tux Term

Create a Launcher for Tux Term

Click OK. You'll now have an icon for Tux Term on your desktop.

Edit the Launcher File

You need to add a line to the launcher file that you just created. Double click on your new icon to launch a terminal for the next step.

cd ~/Desktop
gedit "Tux Term.desktop"

Add the following line to the end of the file and save it.

Categories=Utility

The Utility category will make the menu item show up in Applications->Accessories. For the full list of categories, see the GNOME Menu spec for Registered Categories.

Copy the Launcher File to the System Directory

Enter the following terminal command:

echo $XDG_DATA_DIRS

You should get something that looks like

/usr/local/share/:/usr/share/:/usr/share/gdm/

Your output might be slightly different. This means that I can put a launcher file in any of the three directories listed. If your system doesn't list a directory, then put your file in /usr/share/applications/. In my case, /usr/local/share/applications/ seems like the best location. You need to be the root user to copy the file to the system directory.  It's easiest to use the terminal.

cd ~/Desktop
sudo cp "Tux Term.desktop" /usr/local/share/applications

Edit the System Menu

Check to see that the $XDG_CONFIG_DIRS variable is set.

echo $XDG_CONFIG_DIRS

If you got output from that, then edit the menu file with:

sudo gedit $XDG_CONFIG_DIRS/menus/applications.menu

If your echo command did not yield a result, then edit the /etc/xdg/menus/applications.menu file.

sudo gedit /etc/xdg/menus/applications.menu

Find the following section of the file and add the lines in bold.

<Directory>Accessories.directory</Directory>
<Include>
   <And>
   <Filename>Tux Term.desktop</Filename>
   </And>
   <And>
   <Category>Utility</Category>

Save the file and exit the text editor.

You're new Tux Term launcher will now show up in the Applications->Accessories menu. You can use the User Switcher to log in as a different user and verify that the menu item shows up there as well.

Comments

Leave a Reply