Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 11. 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.
11.1. Multipurpose Internet Mail Extension types Link kopierenLink in die Zwischenablage kopiert!
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
media-type/subtype-identifier
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 project to determine the following information:
- 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.
11.2. Adding a custom MIME type for all users Link kopierenLink in die Zwischenablage kopiert!
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.xmlfile with following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The sample
application-x-newtype.xmlfile here 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.desktopin the/usr/share/applications/with following content:[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_codeCopy to Clipboard Copied! Toggle word wrap Toggle overflow The sample
myapplication1.desktopfile here associates theapplication/x-newtypeMIME type with an application namedMy Application 1. It is run by a commandmyapplication1.Based on how
myapplication1gets started, select one relevant field code from Desktop Entry Specification. For example, for an application capable of opening multiple files, use:Exec=myapplication1 %F
Exec=myapplication1 %FCopy to Clipboard Copied! Toggle word wrap Toggle overflow As a root user, update the MIME database for your changes to take effect.
update-mime-database /usr/share/mime
# update-mime-database /usr/share/mimeCopy to Clipboard Copied! Toggle word wrap Toggle overflow As a root user, update the application database.
update-desktop-database /usr/share/applications
# update-desktop-database /usr/share/applicationsCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
To verify that you have successfully associated
*.xyzfiles with theapplication/x-newtypeMIME 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"
$ touch test.xyz $ gvfs-info test.xyz | grep "standard::content-type" standard::content-type: application/x-newtypeCopy to Clipboard Copied! Toggle word wrap Toggle overflow To verify
myapplication1.desktopis correctly set as the default registered application for theapplication/x-newtypeMIME type, execute following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
11.3. Adding a custom MIME type for individual users Link kopierenLink in die Zwischenablage kopiert!
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.xmlfile with following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The sample
application-x-newtype.xmlfile here defines a new MIME typeapplication/x-newtypeand assigns file names with the.xyzextension 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:[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_codeCopy to Clipboard Copied! Toggle word wrap Toggle overflow The sample
myapplication1.desktopfile above associates theapplication/x-newtypeMIME type with an application named My Application 1. It is run by a commandmyapplication1.Based on how
myapplication1gets started, choose one respective field code from Desktop Entry Specification. For example, for an application capable of opening multiple files, use:Exec=myapplication1 %F
Exec=myapplication1 %FCopy to Clipboard Copied! Toggle word wrap Toggle overflow Update the MIME database for your changes to take effect:
update-mime-database ~/.local/share/mime
$ update-mime-database ~/.local/share/mimeCopy to Clipboard Copied! Toggle word wrap Toggle overflow Update the application database:
update-desktop-database ~/.local/share/applications
$ update-desktop-database ~/.local/share/applicationsCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
To verify that you have successfully associated
*.xyzfiles with theapplication/x-newtypeMIME 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"
$ touch test.xyz $ gvfs-info test.xyz | grep "standard::content-type" standard::content-type: application/x-newtypeCopy to Clipboard Copied! Toggle word wrap Toggle overflow To verify that
myapplication1.desktopis correctly set as the default registered application for theapplication/x-newtypeMIME type, execute following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
11.4. Options to override default MIME types Link kopierenLink in die Zwischenablage kopiert!
By default, the package-installed /usr/share/applications/mimeapps.list and /usr/share/applications/gnome-mimeapps.list files specify the application 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
11.5. Overriding default registered application for all the users Link kopierenLink in die Zwischenablage kopiert!
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.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:[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktop
[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktopCopy to Clipboard Copied! Toggle word wrap Toggle overflow This example above specifies default application (Mozilla Firefox) by specifying its corresponding
.desktopfile (firefox.desktop). You can find.desktopfiles for other applications in the/usr/share/applications/directory.Create the
/etc/xdg/mimeapps.listfile 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
[Default Applications] text/html=myapplication1.desktop application/xhtml+xml=myapplication2.desktopCopy to Clipboard Copied! Toggle word wrap Toggle overflow This example above sets the default registered application for the
text/htmlMIME type tomyapplication1.desktopandapplication/xhtml+xmlMIME type tomyapplication2.desktop.
Verification
-
For these settings to function correctly, ensure that both the
myapplication1.desktopandmyapplication2.desktopfiles are placed in the/usr/share/applications/directory. Verify that the default registered application is set correctly:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
11.6. Overriding default registered application for individual users Link kopierenLink in die Zwischenablage kopiert!
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.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:[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktop
[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktopCopy to Clipboard Copied! Toggle word wrap Toggle overflow This example above specifies default application (Mozilla Firefox) by specifying its corresponding
.desktopfile (firefox.desktop). You can find.desktopfiles for other applications in the/usr/share/applications/directory.Create the
~/.local/share/applications/mimeapps.listfile 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
[Default Applications] text/html=myapplication1.desktop application/xhtml+xml=myapplication2.desktopCopy to Clipboard Copied! Toggle word wrap Toggle overflow This example above sets the default registered application for the
text/htmlMIME type tomyapplication1.desktopandapplication/xhtml+xmlMIME type tomyapplication2.desktop.
Verification
-
For these settings to function correctly, ensure that both the
myapplication1.desktopandmyapplication2.desktopfiles are placed in the/usr/share/applications/directory. Execute the
gio mime querycommand to verify that the default registered application is set correctly.Copy to Clipboard Copied! Toggle word wrap Toggle overflow