Adding/removing associations

Adding and removing associations between mimetypes and applications is done with the following syntax in the mimeapps.list file:

[Added Associations]
[Removed Associations]

[Added Associations] and [Removed Associations] groups may only appear in the non-desktop-specific files (ie: in files that are actually named "mimeapps.list").

The [Added Associations] group defines additional associations of applications with mimetypes, as if the .desktop file was listing this mimetype in the first place.

The [Removed Associations] group removes associations of applications with mimetypes, as if the .desktop file was NOT listing this mimetype in the first place.

Listing the same application for the same type in both the Added and Removed sections is invalid and may produce implementation-defined behaviour.

The order of the entries in the [Added Associations] entry for a given type should be in the "most preferred order", according to the implementation. As such, implementations should take care to preserve the order except in situations where they are explicitly intending to change it.

The adding and removal of associations only applies to desktop files in the current directory, or a later one (in precedence order). This means that additions and removals applied from the mimeapps.list file in $XDG_CONFIG_HOME, $XDG_CONFIG_DIRS and $XDG_DATA_HOME will override all existing desktop files, but that an addition or removal of an association using /usr/share/applications/mimeapps.list, for example, would be ignored if the desktop file of the named application was present in $XDG_DATA_HOME/applications. Put another way: added and removed associations can be thought of as equivalent to copying the desktop file from the next-in-precedence directory with respect to the directory containing the mimeapps.list (which may be the same directory) and tweaking its MimeType= line. If the same .desktop file appears again in a directory with higher precedence order, then this modified .desktop file with lower precedence would be ignored. If the addition or removal refers to a desktop file that doesn't exist at this precedence level, or a lower one, then the addition or removal is ignored, even if the desktop file exists in a high-precedence directory.

The suggested algorithm for listing (in preference order) the applications associated to a given mimetype is:

The above process is repeated for each mimetype from the most specific to the least specific. Note in particular that an application "Added" with a more specific mime type will keep that association, even if it is "Removed" in a higher-precedence directory, using a less specific type.