Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 472  / 2 Years ago, mon, march 21, 2022, 10:42:23

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.


More From » development

 Answers
7

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).


[#43924] Tuesday, March 22, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
laceanz

Total Points: 86
Total Questions: 113
Total Answers: 104

Location: Australia
Member since Thu, Jan 26, 2023
1 Year ago
;