Introduction

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.

Example .desktop file without executable permissions:

not_executable.png

Same file with executable permissions:

executable.png

Using gnome-panel/alacarte

It is important to install gnome-panel using the following command, so as not to install the recommended not-needed packets along with it. So open a terminal using Ctrl+Alt+T and give the following command:

sudo apt-get install --no-install-recommends gnome-panel

It will ask you for your login password, which you have to fill (nothing will be shown, not even asterisks (*)) and press enter.

Without closing the terminal window, after the installation process is over, you have to type the following command:

gnome-desktop-item-edit ~/Desktop/ --create-new

where '~/Desktop/' is any directory you want your launcher to appear, after its creation process is over. After running this command, a familiar window will pop-up, which lets you fill the Name, the Command and the Comment for your launcher. Also, you can specify an icon for your launcher by clicking on the big icon of the window on the top left of it.

You can also use 'alacarte', which you can execute by searching in the Dash for 'Main Menu' and once the application launches, then you click on "New Item" on the section you want your application to be. Then a window similar to the one being shown using the gnome-panel method will be shown.

Adding a .desktop file to the Unity Launcher

In order to add your launcher to the Unity Launcher on the left, you select and drag it onto the Launcher panel. Alternatively, you can 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-validate 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/

Editing an entry of the Unity Launcher

Editing its main characteristics

If you've added a .desktop file to the Unity Launcher, but you don't like something on it, like its icon, or probably it doesn't execute, then you may need to edit the launcher so as to change what you don't like or to fix any errors.

First of all, you have to know the exact name of the .desktop file you will need to edit, and it isn't the same with the application's name (they are usually similar, but still not the same).

So as to find the exact filename of the .desktop file you are interested in, open a terminal using Ctrl+Alt+T and give the following command:

gsettings get com.canonical.Unity.Launcher favorites

This will output a list of all the .desktop files you already have in your launcher, from top to bottom, like this:

['nautilus-home.desktop', 'firefox.desktop', 'filezilla.desktop', 'ubuntu-software-center.desktop', 'qtcreator.desktop', 'ubuntuone-installer.desktop', 'wallch.desktop', 'gnome-terminal.desktop', 'gedit.desktop', 'audacious.desktop', 'gnome-control-center.desktop']

So, by comparing this output to the row of the launchers in your Unity Launcher, you can easily find the name of the .desktop file. For example, if you want to edit the launcher before the last one, in this case it would be 'audacious.desktop'. Copy the name of this launcher by selecting it and giving Ctrl+Shift+C for later use. Now you have in your clipboard the filename of your file, but not its path. Your file can be either under ~/.local/share/applications/ or under /usr/share/applications/. Usually, if you have made a desktop launcher, it is under ~/.local/share/applications, but any other application launcher that belongs to an application you have installed to your computer should be under /usr/share/applications. So, in order to edit this launcher, open a terminal using Ctrl+Alt+T and give the following:

cd /usr/share/applications/
gksudo gedit [paste here what you have in your clipboard with right click->paste or Ctrl+Shift+V]

where 'gedit' you can use your favourite text editor. The following command will ask you for password. Type in your login password and gedit (or any other text editor) will open with the launcher file you wish to edit. To edit the launcher go to 'Using a text editor' where it says it clearly on how to create a launcher and the same applies on editing it.

Adding shortcuts to a launcher

Some applications become much more usable with a right-click menu. This is an example of shortcuts, being used by the application 'Wallch':

shortcuts.png

In this example, the program 'audacious', which is a music player available in the Ubuntu Software Center, will be used as an example of adding shortcuts.

After adding the main characteristics of a launcher, such as filling its 'Name' and 'Exec' fields, then you can add to it one or more shortcuts.

After the 'main body' of the .desktop file, you have to specify the 'actions' you want to add in the 'Actions' field and specify each one of them below. Here's a completely working example of the application 'audacious', providing 3 shortcuts, the Play/Pause, Next and Previous. This is a simplified version of the file:

[Desktop Entry]
Version=1.0
Type=Application
Name=Audacious
GenericName=Music Player
Comment=Listen to music
Icon=audacious
Categories=AudioVideo;Audio;Player;GTK;

Exec=audacious %U

TryExec=audacious

Terminal=false

MimeType=application/ogg;application/x-cue;application/x-ogg;application/xspf+xml;audio/midi;audio/mp3;audio/mpeg;audio/mpegurl;audio/ogg;audio/prs.sid;audio/x-flac;audio/x-it;audio/x-mod;audio/x-mp3;audio/x-mpeg;audio/x-mpegurl;audio/x-ms-wma;audio/x-musepack;audio/x-s3m;audio/x-scpls;audio/x-stm;audio/x-vorbis+ogg;audio/x-wav;audio/x-xm;x-content/audio-cdda;

Actions=PlayPause;Next;Previous

[Desktop Action PlayPause]
Name=Play-Pause
Exec=audacious -t
OnlyShowIn=Unity;

[Desktop Action Next]
Name=Next
Exec=audacious -f
OnlyShowIn=Unity;

[Desktop Action Previous]
Name=Previous
Exec=audacious -r
OnlyShowIn=Unity;

The part that has to do with the shortcuts is everything after 'Actions=' including this. Everything specified on the 'Actions' field has its own name, specified on the 'Name' field of each one. For example, action PlayPause has name Play-Pause, and thus Play-Pause will be displayed on the shortcut in the Unity Launcher once you right click the icon of 'audacious'. Clicking on a shortcut will result on the corresponding action, which means it will execute anything specified in the corresponding 'Exec' field. Each action has its own 'Exec' field, aside from the 'Exec' field specified at the beginning of the file which refers to the action that will take place when you click on the launcher.

Making such shortcuts for applications is generally very easy, unless the application itself doesn't provide enough command line arguments so as to do a corresponding action you would like to. The arguments and what each one does for every application are available through their man page. For example, the arguments '-t', '-f' and '-r' of 'audacious', used on the above example were found though its manual page, using the command

man audacious

, the arrows so as to browse the manual page and the key 'Q' so as to exit.Please, also notice the %U used in the .desktop file above. It is used so as the application to be able to accept an argument when dragging and dropping a file inside the Unity bar on the left. Without it, the program will launch itself, but the argument will not be passed to it and it will be just the same as clicking the application so as to launch.

A thread for discussion of this wiki can be found on the forum at http://ubuntuforums.org/showthread.php?t=2012385

UnityLaunchersAndDesktopFiles (last edited 2013-06-19 02:10:14 by vperetokin)