XDG MIME Applications
There is frequently more than one application able to handle data of a certain type, so users and even some packages assemble lists of default applications for each #MIME type. While the base install of Arch Linux does not define default applications, desktop environments you install may do so. Some desktop environments also provide a GUI or a file-manager which can interactively configure default applications. If you do not use a desktop environment, you may need to install additional software in order to conveniently manage default applications.
- 1 MIME types
- 2 Set default applications
- 3 Utilities
- 4 Troubleshooting
Before setting the default application per file type, the file type must be detected. There are two common ways that this detection is done:
- using the file name extension e.g. .html or .jpeg
- using a magic number in the first few bytes of the file
However it is possible that a single file type is identified by several different magic numbers and file name extensions, therefore MIME types are used to represent distinct file types. MIME types are specified by two parts separated by a slash:
type/subtype. The type describes the general category of the content, while the subtype identifies the specific data type. For example,
image/jpeg is the MIME type for JPEG images, while
video/H264 is the MIME type for H.264 video.
Technically, every MIME type should be registered with the IANA, however many applications use unofficial MIME types; these often have a type starting with
x-, for example
x-scheme-handler/https for a HTTPS URL. For local use, the #MIME database can be used by other packages to register new MIME types.
The system maintains a database of recognized MIME types: the Shared MIME-info Database. The database is built from the XML files installed by packages in
/usr/share/mime/packages using the tools from the package.
The files in
/usr/share/mime/ should not be directly edited, however it is possible to maintain a separate database on a per-user basis in the
New MIME types
This example defines a new MIME type
application/x-foobar and assigns it to any file with a name ending in .foo. Simply create the following file:
<?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="application/x-foobar"> <comment>foo file</comment> <icon name="application-x-foobar"/> <glob-deleteall/> <glob pattern="*.foo"/> </mime-type> </mime-info>
And then update the MIME database
$ update-mime-database ~/.local/share/mime
Each package can use desktop entries to provide information about the MIME types that can be handled by the packaged software. In order to provide fast search in the reverse direction, the system uses the tools from the package to analyze the desktop files and to create an inverse mapping stored in the
/usr/share/applications/mimeinfo.cache file. This is the only file that programs need to read to find all desktop files that might be used to handle given MIME type. Using the database is easier and faster than reading hundreds of .desktop files directly.
The files in
/usr/share/applications/ should not be edited directly, it is possible to maintain a separate database on a per-user basis in the
~/.local/share/applications/ tree. See Desktop entries for details.
Set default applications
The configuration of default applications depends on which launcher is used. Unfortunately there are multiple incompatible standards and many programs even have their own custom formats.
The most common standards are explained below for manual editing. There are also several #Utilities which can do the job, which may or may not implement the following standards.
The XDG standard is the most common for configuring desktop environments. Default applications for each MIME type are stored in
mimeapps.list files, which can be stored in several locations. They are searched in the following order, with earlier associations taking precedence over later ones:
||(deprecated) user overrides|
Additionally, it is possible to define desktop environment-specific default applications in a file named
desktop is the name of the desktop environment (from the
XDG_CURRENT_DESKTOP environment variable). For example,
/etc/xdg/xfce-mimeapps.list defines system-wide default application overrides for Xfce. These desktop-specific overrides take precedence over the corresponding non-desktop-specific file. For example,
/etc/xdg/xfce-mimeapps.list takes precedence over
/etc/xdg/mimeapps.list but is still overridden by
~/.local/share/applications/mimeapps.list. To simplify maintenance, simply symlink it
$ ln -s ~/.local/share/applications/mimeapps.list ~/.config/mimeapps.list. Note that the symlink must be in this direction because #xdg-utils deletes and recreates
~/.local/share/applications/mimeapps.listwhen it writes to it, which will break any symbolic/hard links to
defaults.list. This file is similar to
mimeapps.listexcept it only lists default applications (not added/removed associations). It is now deprecated and should be manually merged with
Consider the following example:
[Added Associations] image/jpeg=bar.desktop;baz.desktop video/H264=bar.desktop [Removed Associations] video/H264=baz.desktop [Default Applications] image/jpeg=foo.desktop
Each section assigns one or more desktop entries to MIME types.
- Added Associations indicates that the applications support opening that MIME type. For example,
baz.desktopcan open JPEG images. This might affect the application list you see when right-clicking a file in a file browser.
- Removed Associations indicates that the applications do not support that MIME type. For example,
baz.desktopcannot open H.264 video.
- Default Applications indicates that the applications should be the default choice for opening that MIME type. For example, JPEG images should be opened with
foo.desktop. This implicitly adds an association between the application and the MIME type. If there are multiple applications, they are tried in order.
Each section is optional and can be omitted if unneeded.
The xdg-open, edit
*/*; xdg-open "%s"
xdg-opento delegate to it. This will cause an infinite loop if you configured your
.mailcapas described above.
While it is possible to configure default applications and MIME types by directly editing #mimeapps.list and the #MIME database, there are many tools that can simplify the process. These tools are also important because applications may delegate opening of files to these tools rather than trying to implement the MIME type standard themselves.
If you use a desktop environment you should first check if it provides its own utility. That should be preferred over these alternatives.
#XDG standard. Most importantly, it provides
/usr/bin/xdg-open which many applications use to open a file with its default application. It is desktop-environment-independent in the sense that it attempts to use each environment's native default application tool and provides its own mechanism if no known environment is detected. Examples:
# determine a file's MIME type $ xdg-mime query filetype photo.jpeg image/jpeg # determine the default application for a MIME type $ xdg-mime query default image/jpeg gimp.desktop # change the default application for a MIME type $ xdg-mime default feh.desktop image/jpeg # open a file with its default application $ xdg-open photo.jpeg # shortcut to open all web MIME types with a single application $ xdg-settings set default-web-browser firefox.desktop # shortcut for setting the default application for a URL scheme $ xdg-settings set default-url-scheme-handler irc xchat.desktop
Because of the complexity of the #xdg-utils version of
xdg-open, it can be difficult to debug when the wrong default application is being opened. Because of this, there are many alternatives that attempt to improve upon it. Several of these alternatives replace the
/usr/bin/xdg-open binary, thus changing the default application behavior of most applications. Others simply provide an alternative method of choosing default applications.
provides the tools
mimetype. These have a slightly nicer interface than their equivalents:
# determine a file's MIME type $ mimetype photo.jpeg photo.jpeg: image/jpeg # choose the default application for this file $ mimeopen -d photo.jpeg Please choose an application 1) Feh (feh) 2) GNU Image Manipulation Program (gimp) 3) Pinta (pinta) use application # # open a file with its default application $ mimeopen -n photo.jpeg
Most importantly, #xdg-utils apps will actually call
mimetype instead of
file for MIME type detection, if it does not detect your desktop environment. This is important because
file does not follow the #XDG standard.
AUR provides the tool
mimeo, which unifies the functionality of
# determine a file's MIME type $ mimeo -m photo.jpeg photo.jpeg image/jpeg # choose the default application for this MIME type $ mimeo --add image/jpeg feh.desktop # open a file with its default application $ mimeo photo.jpeg
However a big difference with xdg-utils is that mimeo also supports custom "association files" that allow for more complex associations. For example, passing specific command line arguments based on a regular expression match:
# open youtube links in VLC without opening a new instance vlc --one-instance --playlist-enqueue %U ^https?://(www.)?youtube.com/watch\?.*v=
AUR patches xdg-utils so that
xdg-open falls back to mimeo if no desktop environment is detected.
AUR provides the tool
whippet, which is similar to
xdg-open. It has X11 integration by using to display errors and to display choices between applications to open.
# open a file with its default application $ whippet -M photo.jpeg # choose from all possible applications for opening a file (without setting a default) $ whippet -m photo.jpeg
In addition to the standard #mimeapps.list, whippet can also use a SQlite database of weighted application/MIME type/regex associations to determine which app to use.
The following packages replace
xdg-open script. These versions of
xdg-open do not do any delegation to desktop-environment-specific tools and do not read/write the standard #mimeapps.list config file (each has its own custom config), so they may not integrate well with other programs that manipulate default applications. However you may find them simpler to use if you do not use a desktop environment.
xdg-*binaries from other than
xdg-openyou should not use these applications, since they do not provide them.
|AUR||Allows regex rules, can specify fallback file opener|
|AUR||Can change command arguments for each MIME type|
|AUR||similar to mimi but also supports regex rules|
|AUR||uses a simple shell-based config file|
AUR provides several methods of searching the MIME database and desktop MIME entries.
For example, to see all MIME extensions in the system's .desktop files that have MIME type
video you can use
lsdesktopf --gm -gx video or to search in the XML database files use
lsdesktopf --gdx -gx video. To get a quick overview of how many and which .desktop files can be associated with a certain MIME type, use
lsdesktopf --gen-mimeapps. To see all file name extensions in XML database files, use
lsdesktopf --gdx -gfx.
If a file is not being opened by your desired default application, there are several possible causes. You may need to check each case.
Missing .desktop file
A desktop entry is required in order to associate an application with a MIME type. Ensure that such an entry exists and can be used to (manually) open files in the application.
If the application's desktop entry does not specify the MIME type under its
MimeType key, it will not be considered when an application is needed to open that type. Edit #mimeapps.list to add an association between the .desktop file and the MIME type.
If the desktop entry is associated with the MIME type, it may simply not be set as the default. Edit #mimeapps.list to set the default association.
Applications are free to ignore or only partially implement the #XDG standard. Check for usage of deprecated files such as
~/.local/share/applications/defaults.list. If you are attempting to open the file from another application (e.g. a web browser or file manager) check if that application has its own method of selecting default applications.
Variables in .desktop files that affect application launch
Desktop environments and file managers supporting the specifications launch programs according to definition in the .desktop files. See Desktop entries#Application entry.
Usually, configuration of the packaged .desktop files is not required, but it may not be bug-free. Even if an application containing necessary MIME type description in the .desktop file
MimeType variable that is used for association, it can fail to start correctly, not start at all or start without opening a file.
This may happen, for example, if the
Exec variable is missing internal options needed for how to open a file, or how the application is shown in the menu. The
Exec variable usually begins with
%; for its currently supported options, see exec-variables.
The following table lists the main variable entries of .desktop files that affect how an application starts, if it has a MIME type associated with it.
|Variable names||Example 1 content||Example 2 content||Description|
|DBusActivatable||DBusActivatable=true||DBusActivatable=false||Application interact with D-Bus. |
See also configuration: D-Bus.
|MimeType||MimeType=application/vnd.oasis.opendocument.text||MimeType=application/vnd.sun.xml.math||List of MIME types supported by application|
|StartupWMClass||StartupWMClass=google-chrome||StartupWMClass=xpad||Associate windows with the owning application|
|Terminal||Terminal=true||Terminal=false||Start in default terminal|