Modifying MIME types
You should never directly modify the source XML files that are
installed to the <MIME>/packages directory by
applications. Instead, modify the Overrides.xml file.
This file has precedence over all other source XML files installed into
the same packages directory. If you are an
application author, then this rule does not apply. You should create a new
source XML file and place it in the proper
<MIME>/packages directory (your
Makefile will take care of this, of course).
You can modify the MIME database for all users on the system or for
a particular user depending on the location of the file you change. To
modify the database for all users, make changes to the file
Overrides.xml in the
$XDG_DATA_DIRS/mime/packages
directory. To modify the database for a single user, make changes to the
file Overrides.xml in the
$XDG_DATA_HOME/mime/packages
directory.
After changes are made, you must always run the
update-mime-database application, with the
directory location of the MIME database as the first parameter.
Adding or Modifying MIME types
To add one or more MIME types for all users:
Create or modify an existing
Overrides.xml source XML file, containing the
definitions for the MIME types. For more information, see the section called “The source XML files”.
Place the Overrides.xml file in the
/usr/share/mime/packages directory.
-
Update the MIME database by running
update-mime-database using the system
account.
update-mime-database /usr/share/mime
To add one or more MIME types for a single user, follow the same
steps, except place your Overrides.xml file in the
~/.local/share/mime/packages directory.
Additionally, call update-mime-database with
~/.local/share/mime/packages as the first
parameter.
After you have made a change to the MIME database and refreshed
its contents, you can verify that the change has taken effect using the
gnomevfs-info application. This application
prints the MIME type and other useful information about a file.
Running gnomevfs-info on a SVG file
gives you the output shown below. You'll notice the default application
for this MIME type is eog.desktop; We will discuss
default applications in the section called “Registering Applications for MIME Types”.
$ gnomevfs-info mime-diagram.svg
Name : mime-diagram.svg
Type : Regular
MIME type : image/svg+xml
Default app : eog.desktop
Size : 14869
Blocks : 32
I/O block size : 4096
Local : YES
SUID : NO
SGID : NO
Sticky : NO
Permissions : 600644
Link count : 1
UID : 1000
GID : 100
Access time : Wed Feb 22 18:24:47 2006
Modification time : Wed Feb 22 18:24:42 2006
Change time : Wed Feb 22 18:24:42 2006
Device # : 775
Inode # : 297252
Readable : YES
Writable : YES
Executable : NO
$
the section called “application/x-newtype Example” walks through the steps of
creating a new MIME type and then verifying the changes using
gnomevfs-info.
application/x-newtype Example
To create (or override) a MIME type and verify the changes:
Make a new, empty file in your home directory called
testing.xyz.
Use gnomevfs-info on the file to
find out the MIME type.The MIME type for this file should be
detected as text/plain because there are not any
glob patterns or magic rules that match it[4].
Create (or modify) the Overrides.xml file
as described in the section called “Adding or Modifying MIME types” with the
contents given in Example 5.3, “Overrides.xml file”.
Refresh the database using
update-mime-database.
-
Use gnomevfs-info to verify that
your change has taken effect. You should see the MIME type for the
testing.xyz file resolved as
application/x-newtype.
$ gnomevfs-info testing.xyz | grep MIME
MIME type : application/x-newtype
$
Example 5.3. Overrides.xml file
<?xml version='1.0' encoding='utf-8'?>
<mime-info xmlns="https://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>