Chapter 7. Configuring file associations You can configure 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: In the image/jpeg MIME type name, 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 about 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 can add a custom MIME type for all the users on the system and register a default application for that MIME type. Procedure 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. Create a new .desktop file named, for example, myapplication1.desktop in the /usr/share/applications/ with following content: 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 . Based on how myapplication1 gets started, choose one respective field code from Desktop Entry Specification . For example, for an application capable of opening multiple files, use: As a root user, update the MIME database for your changes to take effect. As a root user, update the application database. Verification 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: To verify myapplication1.desktop is correctly set as the default registered application for the application/x-newtype MIME type, execute following command: 7.3. Adding a custom MIME type for individual users You can add a custom MIME type for individual user on the system and register a default application for that MIME type. Procedure 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. Create a new .desktop file named, for example, myapplication1.desktop , and place it in the ~/.local/share/applications/ directory with following content: 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 . Based on how myapplication1 gets started, choose one respective field code from Desktop Entry Specification . For example, for an application capable of opening multiple files, use: Update the MIME database for your changes to take effect: Update the application database: Verification 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: To verify that myapplication1.desktop is correctly set as the default registered application for the application/x-newtype MIME type, execute following command: 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: /usr/share/applications/ /etc/xdg/ ~/.local/share/application/ Within a particular location, the configurations are applied in the following order: mimeapps.list 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 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: This example above specifies default application (Mozilla Firefox) by specifying its corresponding .desktop file ( firefox.desktop ). You can find .desktop files for other applications in the /usr/share/applications/ directory. Create the /etc/xdg/mimeapps.list file and specify the MIME types and their corresponding default registered applications in this file. 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 For these settings to function correctly, ensure that both the myapplication1.desktop and myapplication2.desktop files are placed in the /usr/share/applications/ directory. Verify that the default registered application is set correctly: 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 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: This example above specifies default application (Mozilla Firefox) by specifying its corresponding .desktop file ( firefox.desktop ). You can find .desktop files for other applications in the /usr/share/applications/ directory. Create the ~/.local/share/applications/mimeapps.list file and specify the MIME types and their corresponding default registered applications in this file. 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 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.

Commands:
media-type/subtype-identifier
<?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>
[Desktop Entry] Type=Application MimeType=application/x-newtype Name=My Application 1 Exec=myapplication1 field_code
Exec=myapplication1 %F
update-mime-database /usr/share/mime
update-desktop-database /usr/share/applications
touch test.xyz gvfs-info test.xyz | grep "standard::content-type" standard::content-type: application/x-newtype
gio mime --query application/x-newtype Default application for 'application/x-newtype': myapplication1.desktop Registered applications: myapplication1.desktop Recommended applications: myapplication1.desktop
<?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>
[Desktop Entry] Type=Application MimeType=application/x-newtype Name=My Application 1 Exec=myapplication1 field_code
Exec=myapplication1 %F
update-mime-database ~/.local/share/mime
update-desktop-database ~/.local/share/applications
touch test.xyz gvfs-info test.xyz | grep "standard::content-type" standard::content-type: application/x-newtype
gio mime --query application/x-newtype Default application for 'application/x-newtype': myapplication1.desktop Registered applications: myapplication1.desktop Recommended applications: myapplication1.desktop
[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktop
[Default Applications] text/html=myapplication1.desktop application/xhtml+xml=myapplication2.desktop
gio mime text/html Default application for 'text/html': myapplication1.desktop Registered applications: myapplication1.desktop firefox.desktop Recommended applications: myapplication1.desktop firefox.desktop
[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktop
[Default Applications] text/html=myapplication1.desktop application/xhtml+xml=myapplication2.desktop
gio mime text/html Default application for 'text/html': myapplication1.desktop Registered applications: myapplication1.desktop firefox.desktop Recommended applications: myapplication1.desktop firefox.desktop