Unity launchers

Unity Launchers are actually files stored in your computer, with a ‘.desktop’ extension. In earlier Ubuntu versions, these files were simply used so as to launch a specific application, but in Unity they are also used so as to create right-click menus for each application, which you can access from the Unity Launcher. This article […]

Unity Launchers are actually files stored in your computer, with a ‘.desktop’ extension. In earlier Ubuntu versions, these files were simply used so as to launch a specific application, but in Unity they are also used so as to create right-click menus for each application, which you can access from the Unity Launcher.

This article describes how to create a working .desktop file for general use, but also how to add it to the Unity Launcher and/or how to edit a Unity Launcher itself, by editing its fields or by adding a right-click menu to it.

 

Creating a working .desktop file

There are currently 2 ways of creating a desktop file. The 1st one is using a text editor, like Gedit, and the 2nd one is installing a program (gnome-panel) or using ‘alacarte’ that both do the job for you. The former lets you “control” your launcher more than the latter, but the latter way is easier. Please note that this section will cover only the basics, not how to add shortcuts to your launcher. For this, please head to Adding shortcuts to a launcher.

Using a text editor

Open your favourite text editor, like Gedit or nano, and type in (copy and paste):

[Desktop Entry]
Version=x.y
Name=ProgramName
Comment=This is my comment
Exec=/home/alex/Documents/exec.sh
Icon=/home/alex/Pictures/icon.png
Terminal=false
Type=Application
Categories=Utility;Application;

These lines are enough for describing a simple launcher. Each launcher (.desktop file) consists of some basic fields.

  • Version is the version of this .desktop file.
  • Name is the name of the application, like ‘VLC media player’.
  • Comment is a phrase or two describing what this program does, like ‘Plays your music and videos files’.
  • Exec is the path to the executable file. The full path to the executable file must be used only in case it isn’t in any of the paths specified in the $PATH variable. For example, any files that are inside the path /usr/bin don’t need to have their full path specified in the Exec field, but only their filename. To see all the paths in the $PATH variable you can open a terminal using Ctrl+Alt+T and type in
    echo $PATH
  • Icon field is the icon that should be used by the launcher and represents the application. All icons that are under the directory /usr/share/pixmaps don’t need to have their full path specified, but their filename without the extension. For example, if the icon file is /usr/share/pixmaps/wallch.png, then the Icon field should be just ‘wallch’. All other icons should have their full path specified.
  • Terminal field specifies whether the application should run in a terminal window or not.
  • Type field specifies the type of the launcher file. The type can be Application, Link or Directory, but this article covers the ‘Application’ type.
  • Categories field specifies the category of the application. It is used by the Dash so as to categorize the applications. A launcher being a ‘Utility;Application;’ should be under the ‘Accessories’ section etc.

A realistic example of how a .desktop file looks like is the following:

[Desktop Entry]
Version=1.0
Name=BackMeUp
Comment=Back up your data with one click
Exec=/home/alex/Documents/backup.sh
Icon=/home/alex/Pictures/backup.png
Terminal=false
Type=Application
Categories=Utility;Application;

One last thing to add is that by setting executable rights to your .desktop file, it automatically takes the specified Icon and Name (specified in the corresponding fields), as it should be. Be careful though, the filename doesn’t really change, it still remains ‘launcher_name_here.desktop’ and not ‘Name_field_here’, the system chooses to display it like ‘Name_field_here’ because it’s nicer without the .desktop extension.

Adding a .desktop file to the Unity Launcher

In order to add your launcher to the Unity Launcher on the left, you have to place your .desktop file at /usr/share/applications/ or at ~/.local/share/applications/. After moving your file there, search for it in the Dash (Windows key -> type the name of the application) and drag and drop it to the Unity Launcher. Now your launcher (.desktop file) is locked on the Unity Launcher! If your desktop file cannot be found by doing a search from the Dash, you may need to read on…

To be more certain that your .desktop file will work properly, use the desktop file validator, which will notify you of any errors or omissions. If there are no errors, desktop-file-validator will exit silently.

Once the file validates correctly, install it to the default location (probably /usr/share/applications) using the desktop-file-install program. This step may require superuser privileges. The desktop-file-install program may add some lines of its own to your .desktop file. There is no need to have the .desktop file be executable by anyone.

Please note that desktop-file-validate tends to be oversensitive at times, which means that it can output error messages on perfectly working .desktop files. Those error messages should be better seen as warnings rather than anything else. For more information on desktop entry specification please refer to http://standards.freedesktop.org/desktop-entry-spec/latest/