<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Association between MIME types and applications</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="article"><div class="titlepage"><div><div><h2 class="title"><a name="index"></a>Association between MIME types and applications</h2></div><div><div class="authorgroup"><h3 class="corpauthor">
      <a class="ulink" href="http://www.freedesktop.org" target="_top">X Desktop Group</a>
    </h3><div class="author"><h3 class="author"><span class="firstname">David</span> <span class="surname">Faure</span></h3><div class="affiliation"><div class="address"><p><br>
            <code class="email"><<a class="email" href="mailto:faure@kde.org">faure@kde.org</a>></code><br>
          </p></div></div></div></div></div><div><p class="releaseinfo">Version 1.0</p></div><div><p class="pubdate">April 2, 2014</p></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="sect1"><a href="#idm140604128463808">Introduction</a></span></dt><dt><span class="sect1"><a href="#file">File name and location</a></span></dt><dt><span class="sect1"><a href="#default">Default Application</a></span></dt><dt><span class="sect1"><a href="#associations">Adding/removing associations</a></span></dt><dt><span class="sect1"><a href="#ordering">Application ordering</a></span></dt></dl></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="idm140604128463808"></a>Introduction</h2></div></div></div><p>The freedesktop.org <a class="ulink" href="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec/" target="_top">Shared MIME database</a> provides a single way to store static information about MIME types and rules for determining a type.</p><p>The freedesktop.org <a class="ulink" href="http://www.freedesktop.org/wiki/Specifications/desktop-entry-spec/" target="_top">Desktop Entry specification</a> allows applications to announce which MIME types they support.</p><p>This specification solves the remaining issues: which application should open a file by default, how to let the user change the default application, and how to let the user add or remove associations between applications and mimetypes.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="file"></a>File name and location</h2></div></div></div><p>Users, system administrators, application vendors et distributions can change associations between applications and mimetypes by writing into a file called mimeapps.list.</p><p>The lookup order for this file is as follows:</p><div class="informaltable"><table border="1"><colgroup><col><col></colgroup><tbody><tr><td>$XDG_CONFIG_HOME/$xdc-mimeapps.list</td><td>user overrides, desktop-specific (for advanced users)</td></tr><tr><td>$XDG_CONFIG_HOME/mimeapps.list</td><td>user overrides (recommended location for user configuration GUIs)</td></tr><tr><td>$XDG_CONFIG_DIRS/$xdc-mimeapps.list</td><td>sysadmin and ISV overrides, desktop-specific</td></tr><tr><td>$XDG_CONFIG_DIRS/mimeapps.list</td><td>sysadmin and ISV overrides</td></tr><tr><td>$XDG_DATA_HOME/applications/$xdc-mimeapps.list</td><td>for completeness, desktop-specific</td></tr><tr><td>$XDG_DATA_HOME/applications/mimeapps.list</td><td>for compatibility</td></tr><tr><td>$XDG_DATA_DIRS/applications/$xdc-mimeapps.list</td><td>distribution-provided defaults, desktop-specific</td></tr><tr><td>$XDG_DATA_DIRS/applications/mimeapps.list</td><td>distribution-provided defaults</td></tr></tbody></table></div><p>In this table, $xdc means the lowercase version of $XDG_CURRENT_DESKTOP (for instance, kde, gnome, xfce, etc.)</p><p>All of the above files are referred to as "mimeapps.list" in the rest of this specification, for simplicity.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="default"></a>Default Application</h2></div></div></div><p>Indicating the default application for a given mimetype is done by writing into the group [Default Applications] in the file mimeapps.list.</p><p>The [Default Applications] group indicates the preferred application for a given mimetype. This is for instance the one that will be started when left-clicking on a file in a file manager. If the application is no longer installed, the next application in the list is used.</p><p>This example ensures that the application default1.desktop will be used for mimetype1, if it's installed, and otherwise default2.desktop if it's installed:
    </p><pre class="programlisting">
[Default Applications]
mimetype1=default1.desktop;default2.desktop</pre><p>
  </p><p>In the absence of such an entry, the next mimeapps.list is checked. Once all levels have been checked, if no entry could be found, the implementations can pick any of the .desktop files associated with the mimetype, taking into account added and removed associations as per the previous section.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="associations"></a>Adding/removing associations</h2></div></div></div><p>Adding and removing associations between mimetypes and applications is done with the following syntax in the mimeapps.list file:
    </p><pre class="programlisting">
[Added Associations]
mimetype1=foo1.desktop;foo2.desktop;foo3.desktop
mimetype2=foo4.desktop
[Removed Associations]
mimetype1=foo5.desktop</pre><p>
  </p><p>The [Added Associations] group defines additional associations of applications with mimetypes, as if the .desktop file was listing this mimetype in the first place.</p><p>The entries in [Default Applications] should also be considered to add an association between application and mimetype in the same manner.</p><p>The [Removed Associations] group removes associations of applications with mimetypes, as if the .desktop file was NOT listing this mimetype in the first place.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ordering"></a>Application ordering</h2></div></div></div><p>The suggested algorithm for listing the applications associated to a given mimetype is:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>add any "Default Applications" and then "Added Associations" in the first mimeapps.list</p></li><li class="listitem"><p>make a blacklist with the "Removed Associations" in the first mimeapps.list</p></li><li class="listitem"><p>add any "Default Applications" and then the "Added Associations" in the second mimeapps.list, except those in the current blacklist</p></li><li class="listitem"><p>append to the blacklist the "Removed Associations" in the second mimeapps.list</p></li><li class="listitem"><p>repeat the last two steps for all subsequent mimeapps.list files</p></li><li class="listitem"><p>finish by adding the mimetypes listed in the .desktop file, except those in the blacklist</p></li></ul></div></div></div></body></html>