Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I was wondering how Ubuntu is able to figure out the proper name of an application. For example, when you select Open with -> Other application from the context menu, you are presented with this list.

app list

How does a developer teach Ubuntu the name of their application, and how can another developer retrieve the name of an application from the system? I don't need actual code, rather I'm just interested in the conceptual side of things.

share|improve this question

2 Answers 2

up vote 8 down vote accepted

This is specified in an application's desktop entry file. Desktop entry files are launchers for the application (the same file format as the launchers you can create on your desktop) which also contain various metadata. When an application is installed these desktop entry files are placed in /usr/share/applications and I think their contents is also cached to improve speed.

The important piece of data defined here is list of MIME types that the application can open. This is defined in the 'MimeType' key in the desktop entry file. For example, GIMP has the following in its desktop entry:

MimeType=application/postscript;application/pdf;image/bmp;image/g3fax;image/gif;image/x-fits;image/pcx;image/x-portable-anymap;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-psd;image/x-sgi;image/x-tga;image/x-xbitmap;image/x-xwindowdump;image/x-xcf;image/x-compressed-xcf;image/tiff;image/jpeg;image/x-psp;image/png;image/x-icon;image/x-xpixmap;image/svg+xml;image/x-wmf;

This specifies a list of file types that GIMP can open.

The application name is specified with the 'Name' key, eg.

Name=GIMP Image Editor

As you can see, there are icons next to the names. These are also specified in the desktop entry file as either an icon name (for which the correct file is looked up from the icon theme) or an icon file path. GIMP has the following:

Icon=gimp

In the 'Open with -> Other application' dialog, the Recommended Applications are the applications which specify that they are able to open the file type and the Other Applications are those which haven't.

When you have chosen the application, the file manager looks up how to run the application to open the file(s). It looks for the 'Exec' key in the desktop entry. GIMP has the following Exec key:

Exec=gimp-2.6 %U

This means that the command:

gimp-2.6 %U

will be run to open the file(s) with %U replaced with a list of URLs (normally file:// urls) representing the files that have been selected for opening. In addition to '%U', the application may use '%u' for a single url or '%f'/'%F' for a single/multiple file path(s).

share|improve this answer

That is pretty easy. There are .desktop files which contain this info:

[Desktop Entry]
Name=Image Viewer
Comment=Browse and rotate images
Exec=eog %U
Type=Application
Categories=GNOME;GTK;Graphics;RasterGraphics;Viewer;
MimeType=image/bmp;image/gif;image/jpeg;image/jpg;image/pjpeg;image/png;image/tiff;image/x-bmp;image/x-gray;image/x-icb;image/x-ico;image/x-png;image/x-portable-anymap;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-xbitmap;image/x-xpixmap;image/x-pcx;image/svg+xml;image/svg+xml-compressed;image/vnd.wap.wbmp;

You can see them in /usr/share/applications

share|improve this answer

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.