Posted by & filed under Hacks.

This quick guide will show you how to create gnome menus in Ubuntu that can be shared between multiple users – handy if you want to create a default menu structure that will be loaded for each user on a multiuser system. The launchers created will be installed for all users on the system.

I’ve used Ubuntu 10.10 Maverick in the following, but the guide should be working on other versions and distros (that use gnome and xdg-desktop-menu) also.

The Ubuntu Gnome menu

The menu consists of a tree-like structure. The structure is automatically populated when you install programs through apt or synaptic:

Gnome menu structure

Since I wanted to create a sample menu with pentest tools, I’ll add the popular network scanning tool nmap to a folder structure under the main menu:

Applications
|-Other
  |-nmap

The final menu will look like this:

To create the structure we’re going to install the application, create launcher file for it, and then add the launcher to the menu using xdg-desktop-menu.

Intalling the application

To install the tool we need, let’s issue the following command:

sudo apt-get install nmap

Creating the launcher

The easiest way to create the launcher is to create it using the Create Launcher option in Gnome. But first, let’s make sure that we are able to share the launcher with all the other users on the machine by typing the following in a terminal:

sudo mkdir /usr/local/share/applications

It is crucial that the above folder is created, the following commands will strangely not work if this directory doesn’t exist (it will instead install the nmap.desktop file to /usr/share/applications, which did not update the menu on my system).

Create a shell script to launch nmap in the Terminal

You can skip this step if you’re following this guide just to install a GUI applicaiton to the menu and share it between users.

To be able to execute nmap in a shell when we select it in the menu (BackTrack style), we must create a small helper script to prevent the terminal from shutting down the moment the nmap command terminates. . The only thing the following bash script does is exactly this:

[bash]#!/bin/bash
/usr/bin/nmap
exec $SHELL[/bash]

We’ll put this script in a script catalog just below where the launcher will be stored:

cd /usr/local/share/applications
sudo mkdir script
sudo sh -c "echo -e '#!/bin/bash\n/usr/bin/nmap\nexec $SHELL' \
> script/nmap.sh"
sudo chmod +x script/nmap.sh

Use Create Launcher to, uhm… create the launcher

To create the launcher, we simply use the Create Launcher (duh!) option in Ubuntu; right click on the desktop, and select Create Launcher:

Create Launcher menu (right click on desktop)

In the following dialog, enter the name, path to the nmap shell script (or the binary/script of the application you want to launch) and a comment like below:

Check that the launcher works by double-clicking it.

Creating the menu

Finally, to create the menu entry, enter the following command in a terminal window:

sudo xdg-desktop-menu install --novendor --mode system \
nmap.desktop

This should create a new entry in your menu under the Other category, and the link should bring up nmap in a Terminal window when clicked. This menu entry should also show up in all other user’s menus. Result:

Nmap output BT4-style

8 Responses to “Share menus between users in Ubuntu”

  1. Andre

    Really weird thing! Can’t make your article happen here.

    I already have some users in the machine and when following your article the launcher does not appear to these existing users, BUT it does appear for a added user after the xdg-desktop-menu procedure.

    Reply
    • andre

      Oopsss , clicked the submit button before finishing….

      I’m trying to install the Zoiper softphone for all users and I copied files to directory that users can read:
      zoiper.png icon -> /usr/share/icons/
      zoiper binary -> /usr/bin/
      .desktop -> /usr/share/app-install/desktop

      Executed the “xdg-desktop-menu install –novendor –mode system zoiper.desktop”.

      I’m currently using Maverick Meerkat

      One question: What file did you put in the usr/local/shared/applications ? Only the script file for nmap?

      Best Regards!

      Andre

      Reply
      • Andre

        Found out why icon don´t appear for some users, and I don´t know if this is a bug. But it surely look as one.

        After accidentaly running my install script as the user, and not as the superuser, the launcher stopped showing up for this user. All other users existing or new ones gets the launcher on their menus.

        Uninstalling with xdg-desktop-menu application don´t work when this happens and you have to manually remove the .desktop file from the “.local/share/applications” under the user directory.

        It looks like when xdg parses the menu and find conflicting icons, instead of one of them being picked up by the xdg parsers, the user launcher should be the obvious choice and not the system launcher. It simply ignores both of them, and does not display the launcher at all.

        Regards,

        Reply
        • Carsten

          Nicely spotted! Tested this myself, and I can confirm what you have observed. Agree that the default behavior of xgd should be to select the user launcher, seems like a bug to me…

          Reply
  2. Andre

    Okay, Made a fresh install of Ubuntu and re-read your instructions to understand what´s happening here.

    1st) You got a typo under the create a launcher. It´s not ‘shared’ but ‘share’ in the “sudo mkdir /usr/local/share/applications/”. This directory does not exists on my installation, and it must exist to xdg-desktop-menu to work properly as you noted.

    2nd) Your script nmap.sh can exists on any directory with world readable permissions. The above directory is where xdg store the common launcher files of the main-menu. You can verify this by installing and uninstalling the launcher on the menu and verifying that it copy or remove the launcher to this directory.

    And yes, It worked correctly after re-reading your article and with a little time to understand what was happening.

    I also discovered that if you put an icon file with the same name as the binary under the icons folder (/usr/share/icons/), the launcher wizard will automatically load that for you.

    Best Regards!

    Reply
  3. Shawn Powers

    Holy buttspank on toast. I’ve been working for days trying to figure out how to add menu items for all my users. (I’m using LTSP, so literally hundreds of computers, probably 1000 users) I’ve edited files in /usr/share, I’ve created complex XML directory files, I’ve tried manipulating XDG environment variables, and nothing worked.

    You’ve made my day. I’m going to post your procedure on Linux Journal, linking back to you and give you credit. Thanks again, if you’re ever at a tech conference and I’m there, I owe you a $BEVERAGE_OF_CHOICE.

    Reply
    • Carsten

      Glad to be of help! I might take you up on that beverage offer, to be honest I struggled for weeks before I figured out how to do this myself. Maybe XDG should rethink how they do this… Feel free to spread the word.

      Reply

Leave a Reply

  • (will not be published)