How To Write Desktop Files (Linux)

Desktop-files are part of a standard by for defining the behaviour of applications running on Xorg (an X-server implementation). In an GNOME or KDE environment most applications conveniently include a desktop-file. I mostly write desktop files for GUI applications not coming with one and as a way to connect GUI-users with shell scripts.

For an simple example let’s assume that on a certain distribution Thunderbird doesn’t come with an desktop-file. Pretty much the only way to start Thunderbird in such a situtation is by typing thunderbird in the command-line. As desktop files define where in the menus/applications a program can be found, without one you won’t find the application in your menus/applications. Especially for inexperienced users this might cause a lot of confusion and ultimately frustration because they downloaded a program they can’t find anywhere.

The simple solution

A simple and fast solution would be to place an executable shell-script ( which calls thunderbird on the desktop, this way they can double-click the script to open thunderbird. The script would look like this:


Use chmod +x ~/Desktop/ to make the script executable. This helps but is no elegant solution. The script has no icon and the user still can’t find the program in menus/applications.

The appropriate solution

A better solution would be to write a simple desktop file like the one below and store it in ‘/usr/share/applications’, we’ll explain the details later.

#!/usr/bin/env xdg-open
[Desktop Entry]
Comment="Mail Client"

The first line is the shebang which defines how to execute the script, for desktop files #!/usr/bin/env xdg-open is the way to go.
The second line is the group header which should be [Desktop Entry].
The following entries are key value pairs defining the behaviour of the application, for a list of valid keys take a look at this specification by

  • Comment is some additional information for the program
  • Terminal is a boolean defining if a visible terminal should be opened or not
  • Name is the application name
  • Exec is the command which should be executed
  • Type defines the desktop-entry type, in most cases this will be Application
  • Icon is the name of the icon which should be used to represent the application
  • Categories are the categories the application is connected with, in a hierarchical menu this is where the application can be found

Placing this simple desktop-file in an appropriate location like /usr/share/applications tells the system how to show call and represent Thunderbird (shown in image below). This way an inexperienced user can find the application in the menus/applications as well as link it to the desktop/launcher or wherever he wants.

For adding icons to self-written scripts I google the most appropriate buzz-word and add icon like vnc icon. This usually results instantly in proper icons for my script which I save to /usr/share/pixmaps/ and reference in the desktop-file with Icon="application-name.png".


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: