12.3. Configuring File Associations
12.3.1. What Are MIME Types?
- Determine which application should open a specific file format by default.
- Register other applications that can also open a specific file format.
- Provide a string describing the type of a file, for example, in a file properties dialog of the Files application.
- Provide an icon representing a specific file format, for example, in a file properties dialog of the Files application.
media-type/subtype-identifier
media-type/subtype-identifierExample 12.7. MIME Types Format
image/jpeg is an example of a MIME type where image is the media type, and jpeg is the subtype identifier.
- The machine-wide and user-specific location to store all MIME type specification files.
- How to register a MIME type so that the desktop environment knows which applications can be used to open a specific file format.
- How the user can change which applications should open what file formats.
12.3.1.1. What Is the MIME Database?
/usr/share/mime/packages/ directory where the MIME type related files specifying information on known MIME types are stored. One example of such a file is /usr/share/mime/packages/freedesktop.org.xml, specifying information about the standard MIME types available on the system by default. That file is provided by the shared-mime-info package.
Getting More Information
12.3.2. Adding a Custom MIME Type for All Users
/usr/share/mime/packages/ directory and a .desktop file in the /usr/share/applications/ directory.
Procedure 12.3. Adding a Custom application/x-newtype MIME Type for All Users
- Create the
/usr/share/mime/packages/application-x-newtype.xmlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow <?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="application/x-newtype"> <comment>new mime type</comment> <glob pattern="*.xyz"/> </mime-type> </mime-info><?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="application/x-newtype"> <comment>new mime type</comment> <glob pattern="*.xyz"/> </mime-type> </mime-info>The sampleapplication-x-newtype.xmlfile above defines a new MIME typeapplication/x-newtypeand assigns file names with the.xyzextension to that MIME type. - Create a new
.desktopfile named, for example,myapplication1.desktop, and place it in the/usr/share/applications/directory:Copy to Clipboard Copied! Toggle word wrap Toggle overflow [Desktop Entry] Type=Application MimeType=application/x-newtype Name=My Application 1 Exec=myapplication1 field_code
[Desktop Entry] Type=Application MimeType=application/x-newtype Name=My Application 1 Exec=myapplication1 field_codeThe samplemyapplication1.desktopfile above associates theapplication/x-newtypeMIME type with an application named My Application 1, which is run by the commandmyapplication1.Based on howmyapplication1gets started, choose one respective field code from Desktop Entry Specification. For example, for an application capable of opening multiple files, use:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Exec=myapplication1 %F
Exec=myapplication1 %F - As root, update the MIME database for your changes to take effect:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow update-mime-database /usr/share/mime
# update-mime-database /usr/share/mime - As root, update the application database:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow update-desktop-database /usr/share/applications
# update-desktop-database /usr/share/applications - To verify that you have successfully associated
*.xyzfiles with theapplication/x-newtypeMIME type, first create an empty file, for exampletest.xyz:Copy to Clipboard Copied! Toggle word wrap Toggle overflow touch test.xyz
$ touch test.xyzThen run thegvfs-infocommand:Copy to Clipboard Copied! Toggle word wrap Toggle overflow gvfs-info test.xyz | grep "standard::content-type"
$ gvfs-info test.xyz | grep "standard::content-type" standard::content-type: application/x-newtype - To verify that
myapplication1.desktophas been correctly set as the default registered application for theapplication/x-newtypeMIME type, run thegvfs-mime --querycommand:Copy to Clipboard Copied! Toggle word wrap Toggle overflow gvfs-mime --query application/x-newtype
$ gvfs-mime --query application/x-newtype Default application for 'application/x-newtype': myapplication1.desktop Registered applications: myapplication1.desktop Recommended applications: myapplication1.desktop
12.3.3. Adding a Custom MIME Type for Individual Users
~/.local/share/mime/packages/ directory and a .desktop file in the ~/.local/share/applications/ directory.
Procedure 12.4. Adding a Custom application/x-newtype MIME Type for Individual Users
- Create the
~/.local/share/mime/packages/application-x-newtype.xmlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow <?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="application/x-newtype"> <comment>new mime type</comment> <glob pattern="*.xyz"/> </mime-type> </mime-info><?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="application/x-newtype"> <comment>new mime type</comment> <glob pattern="*.xyz"/> </mime-type> </mime-info>The sampleapplication-x-newtype.xmlfile above defines a new MIME typeapplication/x-newtypeand assigns file names with the.xyzextension to that MIME type. - Create a new
.desktopfile named, for example,myapplication1.desktop, and place it in the~/.local/share/applications/directory:Copy to Clipboard Copied! Toggle word wrap Toggle overflow [Desktop Entry] Type=Application MimeType=application/x-newtype Name=My Application 1 Exec=myapplication1 field_code
[Desktop Entry] Type=Application MimeType=application/x-newtype Name=My Application 1 Exec=myapplication1 field_codeThe samplemyapplication1.desktopfile above associates theapplication/x-newtypeMIME type with an application named My Application 1, which is run by the commandmyapplication1.Based on howmyapplication1gets started, choose one respective field code from Desktop Entry Specification. For example, for an application capable of opening multiple files, use:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Exec=myapplication1 %F
Exec=myapplication1 %F - Update the MIME database for your changes to take effect:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow update-mime-database ~/.local/share/mime
$ update-mime-database ~/.local/share/mime - Update the application database:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow update-desktop-database ~/.local/share/applications
$ update-desktop-database ~/.local/share/applications - To verify that you have successfully associated
*.xyzfiles with theapplication/x-newtypeMIME type, first create an empty file, for exampletest.xyz:Copy to Clipboard Copied! Toggle word wrap Toggle overflow touch test.xyz
$ touch test.xyzThen run thegvfs-infocommand:Copy to Clipboard Copied! Toggle word wrap Toggle overflow gvfs-info test.xyz | grep "standard::content-type"
$ gvfs-info test.xyz | grep "standard::content-type" standard::content-type: application/x-newtype - To verify that
myapplication1.desktophas been correctly set as the default registered application for theapplication/x-newtypeMIME type, run thegvfs-mime --querycommand:Copy to Clipboard Copied! Toggle word wrap Toggle overflow gvfs-mime --query application/x-newtype
$ gvfs-mime --query application/x-newtype Default application for 'application/x-newtype': myapplication1.desktop Registered applications: myapplication1.desktop Recommended applications: myapplication1.desktop
12.3.4. Overriding the Default Registered Application for All Users
/usr/share/applications/mimeapps.list and /usr/share/applications/[desktop environment name]-mimeapps.list file are the package-installed defaults, which specify which application is registered to open specific MIME types by default.
/etc/xdg/mimeapps.list or /etc/xdg/[desktop environment name]-mimeapps.list file with a list of MIME types for which they want to override the default registered application.
/usr/share/applications//etc/xdg/
mimeapps.list[desktop environment name]-mimeapps.list
Note
defaults.list file instead of the mimeapps.list file.
Procedure 12.5. Overriding the Default Registered Application for All Users
- Consult the
/usr/share/applications/mimeapps.listfile to determine the MIME types for which you want to change the default registered application. For example, the following sample of themimeapps.listfile specifies the default registered application for thetext/htmlandapplication/xhtml+xmlMIME types:Copy to Clipboard Copied! Toggle word wrap Toggle overflow [Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktop
[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktopThe default application (Firefox) is defined by specifying its corresponding.desktopfile (firefox.desktop). The default location for other applications'.desktopfiles is/usr/share/applications/. - Create the
/etc/xdg/mimeapps.listfile. In the file, specify the MIME types and their corresponding default registered applications:Copy to Clipboard Copied! Toggle word wrap Toggle overflow [Default Applications] text/html=myapplication1.desktop application/xhtml+xml=myapplication2.desktop
[Default Applications] text/html=myapplication1.desktop application/xhtml+xml=myapplication2.desktopThis sets the default registered application for thetext/htmlMIME type tomyapplication1.desktop, and the default registered application for theapplication/xhtml+xmlMIME type tomyapplication2.desktop.For these settings to function properly, ensure that both themyapplication1.desktopandmyapplication2.desktopfiles are placed in the/usr/share/applications/directory. - You can use the
gvfs-mime querycommand to verify that the default registered application has been set correctly:Copy to Clipboard Copied! Toggle word wrap Toggle overflow $gvfs-mime query text/html Default application for 'text/html': myapplication1.desktop Registered applications: myapplication1.desktop firefox.desktop Recommended applications: myapplication1.desktop firefox.desktop
$gvfs-mime query text/html Default application for 'text/html': myapplication1.desktop Registered applications: myapplication1.desktop firefox.desktop Recommended applications: myapplication1.desktop firefox.desktop
12.3.5. Overriding the Default Registered Application for Individual Users
/usr/share/applications/mimeapps.list and /usr/share/applications/[desktop environment name]-mimeapps.list file are the package-installed defaults, which specify which application is registered to open specific MIME types by default.
~/.local/share/applications/mimeapps.list or ~/.local/share/applications/[desktop environment id]-mimeapps.list file with a list of MIME types for which you want to override the default registered application.
/usr/share/applications//etc/xdg/~/.local/share/application/
mimeapps.list[desktop environment name]-mimeapps.list
Note
defaults.list file instead of the mimeapps.list file.
Procedure 12.6. Overriding the Default Registered Application for Individual Users
- Consult the
/usr/share/applications/mimeapps.listfile to determine the MIME types for which you want to change the default registered application. For example, the following sample of themimeapps.listfile specifies the default registered application for thetext/htmlandapplication/xhtml+xmlMIME types:Copy to Clipboard Copied! Toggle word wrap Toggle overflow [Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktop
[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktopThe default application (Firefox) is defined by specifying its corresponding.desktopfile (firefox.desktop). The system default location for other applications'.desktopfiles is/usr/share/applications/. Individual users'.desktopfiles can be stored in~/.local/share/applications/. - Create the
~/.local/share/applications/mimeapps.listfile. In the file, specify the MIME types and their corresponding default registered applications:Copy to Clipboard Copied! Toggle word wrap Toggle overflow [Default Applications] text/html=myapplication1.desktop application/xhtml+xml=myapplication2.desktop
[Default Applications] text/html=myapplication1.desktop application/xhtml+xml=myapplication2.desktopThis sets the default registered application for thetext/htmlMIME type tomyapplication1.desktop, and the default registered application for theapplication/xhtml+xmlMIME type tomyapplication2.desktop.For these settings to function properly, ensure that both themyapplication1.desktopandmyapplication2.desktopfiles are placed in the/usr/share/applications/directory. - You can use the
gvfs-mime --querycommand to verify that the default registered application has been set correctly:Copy to Clipboard Copied! Toggle word wrap Toggle overflow $gvfs-mime --query text/html Default application for 'text/html': myapplication1.desktop Registered applications: myapplication1.desktop firefox.desktop Recommended applications: myapplication1.desktop firefox.desktop
$gvfs-mime --query text/html Default application for 'text/html': myapplication1.desktop Registered applications: myapplication1.desktop firefox.desktop Recommended applications: myapplication1.desktop firefox.desktop