Chapter 7. Configuring file associations

This section provides information on configuring RHEL to open or access files with different formats.

In GNOME, MIME (Multipurpose Internet Mail Extension) types help to identify the format of a file and applications to use to open these files.

7.1. Multipurpose Internet Mail Extension types

The GNOME desktop uses MIME types to:

  • Determine which application should open a specific file format by default.
  • Register other applications that can open files of a specific format.
  • Set a string describing the type of a file, for example, in a file properties dialog of the files application.
  • Set an icon representing a specific file format, for example, in a file properties dialog of the files application.

MIME type names follow a given format:

media-type/subtype-identifier

For example, image/jpeg.

Here image is a media type and jpeg is the subtype identifier.

GNOME follows Multipurpose Internet Mail Extension (MIME) info specification from the Freedesktop.org to determine:

  • The machine-wide and user-specific location to store all the MIME type specification files.
  • How to register a MIME type so that the desktop environment knows which application you can use to open a specific file format.
  • How users can change which applications should open with what file formats.

MIME database

The MIME database is a collection of all the MIME type specification files that GNOME uses to store information about known MIME types.

The most important part of the MIME database from the system administrator’s point of view is the /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. The shared-mime-info package provides this file.

Additional resources

  • For detailed information describing the MIME type system, see Shared MIME Info specifications on the Freedesktop website.

7.2. Adding a custom MIME type for all users

You must create a new MIME type specification file in the /usr/share/mime/packages/ directory and a .desktop file in the /usr/share/applications/ directory to add a custom MIME type for all the users on the system and register a default application for that MIME type.

Procedure

  1. Create the /usr/share/mime/packages/application-x-newtype.xml file with following content:

    <?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 sample application-x-newtype.xml file here defines a new MIME type application/x-newtype and assigns file names with the .xyz extension to that MIME type.

  2. Create a new .desktop file named, for example, myapplication1.desktop in the /usr/share/applications/ with following content:

    [Desktop Entry]
    Type=Application
    MimeType=application/x-newtype
    Name=My Application 1
    Exec=myapplication1

    The sample myapplication1.desktop file here associates the application/x-newtype MIME type with an application named My Application 1. It is run by a command myapplication1.

  3. As a root user, update the MIME database for your changes to take effect.

    # update-mime-database /usr/share/mime
  4. As a root user, update the application database.

    # update-desktop-database /usr/share/applications

Verification steps

  1. To verify that you have successfully associated *.xyz files with the application/x-newtype MIME type, first create an empty file, for example test.xyz and execute the following commands:

    $ touch test.xyz
    
    $ gvfs-info test.xyz | grep "standard::content-type"
      standard::content-type: application/x-newtype
  2. To verify myapplication1.desktop is correctly set as the default registered application for the application/x-newtype MIME type, execute following command:

    $ gio mime --query application/x-newtype
    Default application for 'application/x-newtype': myapplication1.desktop
    Registered applications:
    	myapplication1.desktop
    Recommended applications:
    	myapplication1.desktop

7.3. Adding a custom MIME type for individual users

You must create a new MIME type specification file in the ~/.local/share/mime/packages/ directory and a .desktop file in the ~/.local/share/applications/ directory to add a custom MIME type for individual users and register a default application for that MIME type.

Procedure

  1. Create the ~/.local/share/mime/packages/application-x-newtype.xml file with following content:

    <?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 sample application-x-newtype.xml file here defines a new MIME type application/x-newtype and assigns file names with the .xyz extension to that MIME type.

  2. Create a new .desktop file named, for example, myapplication1.desktop, and place it in the ~/.local/share/applications/ directory with following content:

    [Desktop Entry]
    Type=Application
    MimeType=application/x-newtype
    Name=My Application 1
    Exec=myapplication1

    The sample myapplication1.desktop file above associates the application/x-newtype MIME type with an application named My Application 1. It is run by a command myapplication1.

  3. Update the MIME database for your changes to take effect:

    $ update-mime-database ~/.local/share/mime
  4. Update the application database:

    $ update-desktop-database ~/.local/share/applications

Verification steps

  1. To verify that you have successfully associated *.xyz files with the application/x-newtype MIME type, first create an empty file, for example, test.xyz and execute the following commands:

    $ touch test.xyz
    
    $ gvfs-info test.xyz | grep "standard::content-type"
      standard::content-type: application/x-newtype
  2. To verify that myapplication1.desktop is correctly set as the default registered application for the application/x-newtype MIME type, execute following command:

    $ gio mime --query application/x-newtype
    Default application for 'application/x-newtype': myapplication1.desktop
    Registered applications:
    	myapplication1.desktop
    Recommended applications:
    	myapplication1.desktop

7.4. Options to override default MIME types

By default, the package-installed /usr/share/applications/mimeapps.list and /usr/share/applications/gnome-mimeapps.list files specify which application is registered to open specific MIME types.

System administrators can create the /etc/xdg/mimeapps.list or /etc/xdg/gnome-mimeapps.list file with a list of MIME types they want to override with the default registered application.

Local users can create the ~/.local/share/applications/mimeapps.list or ~/.local/share/applications/gnome-mimeapps.list file with a list of MIME types for which they want to override the default registered application.

Configurations are applied in the following order:

  1. /usr/share/applications/
  2. /etc/xdg/
  3. ~/.local/share/application/

Within a particular location, the configurations are applied in the following order:

  1. mimeapps.list
  2. gnome-mimeapps.list

7.5. Overriding default registered application for all the users

As a system administer, you can update the configuration based on the requirements. System administrator’s configuration takes precedence over default package configuration. Within each, the desktop-specific configuration takes precedence over the configuration that does not specify the desktop environment.

Procedure

  1. Consult the /usr/share/applications/mimeapps.list file to determine the MIME types for which you want to change the default registered application. For example, the following sample of the mimeapps.list file specifies the default registered application for the text/html and application/xhtml+xml MIME types:

    [Default Applications]
    text/html=firefox.desktop
    application/xhtml+xml=firefox.desktop

    This example above specifies default application (Firefox) by specifying its corresponding .desktop file (firefox.desktop). You can find .desktop files for other applications in the /usr/share/applications/ directory.

  2. Create the /etc/xdg/mimeapps.list file and specify the MIME types and their corresponding default registered applications in this file.

    [Default Applications]
    text/html=myapplication1.desktop
    application/xhtml+xml=myapplication2.desktop

    This example above sets the default registered application for the text/html MIME type to myapplication1.desktop and application/xhtml+xml MIME type to myapplication2.desktop.

Verification steps

  • For these settings to function correctly, ensure that both the myapplication1.desktop and myapplication2.desktop files are placed in the /usr/share/applications/ directory.
  • Execute the gio mime query command to verify that the default registered application is set correctly.

    $ gio mime text/html
    Default application for 'text/html': myapplication1.desktop
    Registered applications:
    	myapplication1.desktop
    	firefox.desktop
    Recommended applications:
    	myapplication1.desktop
    	firefox.desktop

7.6. Overriding default registered application for individual users

Individual users can also update the configuration based on the requirements. This configuration takes precedence over the system administrator’s configuration and the system administrator’s configuration takes precedence over the package configuration. Within each, the desktop-specific configuration takes precedence over the configuration that does not specify the desktop environment.

Procedure

  1. Consult the /usr/share/applications/mimeapps.list file to determine the MIME types for which you want to change the default registered application. For example, the following sample of the mimeapps.list file specifies the default registered application for the text/html and application/xhtml+xml MIME types:

    [Default Applications]
    text/html=firefox.desktop
    application/xhtml+xml=firefox.desktop

    This example above specifies default application (Firefox) by specifying its corresponding .desktop file (firefox.desktop). You can find .desktop files for other applications in the /usr/share/applications/ directory.

  2. Create the ~/.local/share/applications/mimeapps.list file and specify the MIME types and their corresponding default registered applications in this file.

    [Default Applications]
    text/html=myapplication1.desktop
    application/xhtml+xml=myapplication2.desktop

    This example above sets the default registered application for the text/html MIME type to myapplication1.desktop and application/xhtml+xml MIME type to myapplication2.desktop.

Verification steps

  • For these settings to function correctly, ensure that both the myapplication1.desktop and myapplication2.desktop files are placed in the /usr/share/applications/ directory.
  • Execute the gio mime query command to verify that the default registered application is set correctly.

    $ gio mime text/html
    Default application for 'text/html': myapplication1.desktop
    Registered applications:
    	myapplication1.desktop
    	firefox.desktop
    Recommended applications:
    	myapplication1.desktop
    	firefox.desktop