Registering Applications for MIME Types

Registering applications to handle MIME types is fairly straightforward. Applications are registered by creating a MimeType key in their .desktop entry file and listing each MIME type separated by a semicolon. The MimeType key should only be used in .desktop files whose Type key has the value Application. For more information on .desktop files, see Section 2.3 ― Desktop Entry Files.

After creating or modifying a .desktop entry file, you must update the application database using the update-desktop-database application (very similar to update-mime-database, except it does not take a parameter). This will create a mimeinfo.cache file in the applications subdirectory for each directory in $XDG_DATA_HOME:$XDG_DATA_DIRS. The cache file is necessary so that all the .desktop files do not need to be scanned for just the MimeType key, as this causes unnecessary disk I/O.

Default applications to use for specific MIME types should be specified in a file called defaults.list. This file is located in the applications subdirectory for each directory in $XDG_DATA_HOME and $XDG_DATA_DIRS. The format for this file consists of the MIME type, the = symbol and the Desktop File ID (which is the filename for the desktop entry file). Example 5-4 is a short example of a defaults.list file in a user's ~/.local/share/applications directory.

Example 5-4A User's defaults.list file
[Default Applications]
application/pdf=evince.desktop
text/html=epiphany.desktop
text/plain=gedit.desktop
image/jpeg=eog.desktop
image/png=eog.desktop
text/xml=gedit.desktop
XDG Desktop Entry Specification

How to register MIME types for applications is part of the XDG desktop entry specification, rather than the XDG shared mime info specification.