Skip to content

Instantly share code, notes, and snippets.

@mcarletti
Last active August 27, 2020 12:49
Show Gist options
  • Save mcarletti/83cb3dba70caf55e561dcbbd4736b38c to your computer and use it in GitHub Desktop.
Save mcarletti/83cb3dba70caf55e561dcbbd4736b38c to your computer and use it in GitHub Desktop.
Minimal description and example of a Ubuntu launcher file, aka .desktop file
[Desktop Entry]
Name=Name of Application
GenericName=Application
GenericName[it]=Applicazione
Comment=Cool app, very useful
Comment[it]=Applicazione molto utile e intrigante
Categories=cat1;cat2;...
Keywords=kw1;kw2;...
Encoding=UTF-8
Exec=/path/to/executable
Icon=/path/to/icon
Terminal=false
Type=Application
Version=1.0

What is a desktop file?

A .desktop file is basically a simple text file holding information about a program.
It represents and application that is identified by the name of the desktop file.
When a MyApp.desktop file is created, Ubuntu launcher shows a new icon linked to (and named as) MyApp.
Such a file are also useful to run a software with a double-click on its icon.

What can I run from a desktop file?

Desktop files implements the Exec entry which is the path of the executable.
Executables could be binaries, script or even a command sent to the comman line.
For binaries and scripts, the path must be absolute and cannot be set relative to the desktop file location.

Exec

It could happen the exec command does not work as expected.
For example, the app crashes if not run in a terminal.
In such cases we have three options:

  1. run app in terminal
    Exec=gnome-terminal -- /path/to/executable
    This is particularly usefull when an application (eg. Blender, Matlab) prints its log messages on the standard output/error on the console.

  2. add semicolon (still dunno why, but ehi... it works)
    Exec=/path/to/executable;

  3. exec a script that runs "disown" command
    Exec=/path/to/script/run.sh
    where run.sh is something like:

#!/bin/bash
/path/to/executable &
disown %1

Where I have to put a custom .desktop file?

It is usually placed in ~/.local/share/applications or /usr/share/applications/ depending whether you want the launcher to be accessible only for local account or for everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment