Mime types

Contents

    Here, we are NOT talking about EMAIL MIME types and

    TODO: see how to use /usr/share/mime-info dir.

    See alos: desktop entries chapter.

    Understanding media types (MIME types)

    Media type (aka MIME type)

    A type identifier that uses a standard format called RFC 2045.
    type "/" [tree "."] sub-type ["+" suffix] *[";" parameter]

    Ten types are available: application, audio, example, font, image, message, model, multipart, text and video.
    Four trees are defined: standard tree (without prefix), vendor tree (vnd. prefix), personal tree (prs. prefix) and unregistered tree (x. prefix).

    Example text/html; charset=UTF-8

    Exemples

    Detection of type : Shared MIME info spec database

    Single way to store static information about MIME types and rules for determining a type for a given file.

    Sources

    According to the specs, the databses are located into the mime subdirectory of every directory in XDG_DATA_HOME:XDG_DATA_DIRS. By default, this means:

    A packages directory holds a set of files. Each of them is describing a way to label files with a given type.

    Here is a basic example:

    <?xml version="1.0" encoding="UTF-8"?>
    <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
     <mime-type type="application/x-extension-html">
      <comment>html document</comment>
      <glob pattern="*.html"/>
     </mime-type>
    </mime-info>
    

    Note: a lot of options are available in order to assign a type to a file based on its content or path.

    According to the specs, « Each application that wishes to contribute to the MIME database will install a single XML file, named after the application, into one of the three <MIME>/packages/ directories (depending on where the user requested the application be installed). After installing, uninstalling or modifying this file, the application MUST run the update-mime-database command. »

    The update-mime-database command is processing a database in order to build several files (full list) using the ones stored into the packages folder.
    Example: update-mime-database ~/.local/share/mime

    IMPORTANT
    « Any file named Override.xml takes precedence over all other files in the same packages directory ». « Users should never edit the database. If they wish to make corrections or provide MIME entries for software that doesn't provide these itself, they should do so by means of the Override.xml ».

    Linking MIME types to applications

    Association between MIME types and applications : « 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. »

    mimeapps.list file location

    The information is located into a file called mimeapps.list.

    user overrides, desktop-specific (for advanced users)

    user overrides (recommended location for user configuration GUIs)

    → Best place for user defined config.

    sysadmin and ISV overrides, desktop-specific

    sysadmin and ISV overrides

    DEPRECATED For completeness, desktop-specific

    DEPRECATED For compatibility

    distribution-provided defaults, desktop-specific

    distribution-provided defaults

    mimeapps.list file format

    mimeapps.list can contain the following groups

    Here is a basic example

    [Added Associations]
    image/jpeg=org.gnome.gThumb.desktop;shotwell-viewer.desktop;gimp.desktop;ristretto.desktop;
    audio/mpeg=vlc.desktop;
    
    [Default Applications]
    text/html=firefox.desktop
    image/jpeg=org.gnome.gThumb.desktop
    

    Executables from xdg-utils package

    xdg-mime command

    xdg-open command
    Opens a file or URL in the user's preferred application
    xdg-open myfile.jpg

    NOTE : here are some alternatives to xdg-utils package


    Attachments

    Proudly Powered by Zim 0.75.2.

    Template by Etienne Gandrille, based on ZeroFiveEight and using JQuery Toc Plugin.