Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The GNOME on-board documentation covers only the things anyone can easily guess. I have an application for that I can only start from the command line. Not that I mind using a terminal but ...

Anyway, how do I add the command (and preferably a nice logo) to GNOME WM?

share|improve this question
    
If you right click do you get an "Edit Menu" item? –  slm Nov 30 '13 at 18:42
    
no, no right click menu at all. –  mart Nov 30 '13 at 19:46
1  
GNOME is a desktop environment, not a window manager. The window manager in GNOME 2.x is called Metacity and GNOME3 uses a compositing window manager called Mutter –  Thomas Nyman Nov 30 '13 at 20:20

1 Answer 1

up vote 10 down vote accepted

In GNOME and other freedesktop.org-compliant desktop environments, such as KDE and Unity, applications are added to the desktop's menus or desktop shell via desktop entries, defined in text files with the .desktop extension (referred to as desktop files). The desktop environments construct menus for a user from the combined information extracted from available desktop entries.

Desktop files may be created in either of two places:

  • /usr/share/applications/ for desktop entries available to every user in the system
  • ~/.local/share/applications/ for desktop entries available to a single user

Per convention, desktop files should not include spaces or international characters in their name.

Each desktop file is split into groups, each starting with the group header in square brackets ([]). Each section contains a number of key, value pairs, separated by an equal sign (=).

Below is a sample of desktop file:

[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Application Name
Comment=Application description
Icon=/path/to/icon.xpm
Exec=/path/to/application/executable
Terminal=false
Categories=Tags;Describing;Application

Explanation

  • [Desktop Entry] the Desktop Entry group header identifies the file as a desktop entry
  • Type the type of the entry, valid values are Application, Link and Directory
  • Encoding the character encoding of the desktop file
  • Name the application name visible in menus or launchers
  • Comment a description of the application used in tooltips
  • Icon the icon shown for the application in menus or launchers
  • Exec the command that is used to start the application from a shell.
  • Terminal whether the application should be run in a terminal, valid values are true or false
  • Categories semi-colon (;) separated list of menu categories in which the entry should be shown

Command line arguments in the Exec key can be signified with the following variables:

  • %f a single filename.
  • %F multiple filenames.
  • %u a single URL.
  • %U multiple URLs.
  • %d a single directory. Used in conjunction with %f to locate a file.
  • %D multiple directories. Used in conjunction with %F to locate files.
  • %n a single filename without a path.
  • %N multiple filenames without paths.
  • %k a URI or local filename of the location of the desktop file.
  • %v the name of the Device entry.

Note that ~ or environmental variables like $HOME are not expanded within desktop files, so any executables referenced must either be in the $PATH or referenced via their absolute path.

A full Desktop Entry Specification is available at the GNOME Dev Center.

Launch Scripts

If the application to be launched requires certain steps to be done prior to be invoked, you can create a shell script which launches the application, and point the desktop entry to the shell script. Suppose that an application requires to be run from a certain current working directory. Create a launch script in a suitable to location (~/bin/ for instance). The script might look something like the following:

#!/bin/sh
pushd "/path/to/application/directory"
./application "$@"
popd

Set the executable bit for the script:

$ chmod +x ~/bin/launch-application

Then point the Exec key in the desktop entry to the launch script:

Exec=/home/user/bin/launch-application
share|improve this answer
    
I did that, I can see the icon under applications, but when I click the app does not start, the cursor only changes to a loading symbol for a few seconds. No error message. –  mart Dec 1 '13 at 8:49
    
@mart Can you tell us which application you are trying to add a launcher for? –  Thomas Nyman Dec 1 '13 at 11:21
    
FTL - an indie game I bought somewhere on the web. Starting from Console works. –  mart Dec 1 '13 at 15:12
    
to add: from the console, I call the game with cding to the directory and calling it with ./FTL. When I enter <path>/.FTL in the .desktop file, I get the error message that the executable cannot be found. When I leave the dot out, I get the result described above. –  mart Dec 1 '13 at 16:18
    
@mart <path>/.FTL would point to a hidden file called .FTL, which is not the same as ./FTL, which points to a file called FTL in the current directory. You can try to launch FTL via /full/path/path/to/FTL in a terminal to see if you get any meaningfull error output. For instance, if the executable searches for libraries in the current working directory, you might have to do a launcher script which does something along the lines of pushd <path>; ./FTL; popd and point the Exec specifier in the desktop file to the launcher script instead. –  Thomas Nyman Dec 1 '13 at 16:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.