1<page xmlns="http://projectmallard.org/1.0/" 2 type="topic" style="task" 3 id="mime-types-custom"> 4 5 <info> 6 <link type="guide" xref="software#management" /> 7 <link type="seealso" xref="mime-types" /> 8 <link type="seealso" xref="mime-types-custom-user" /> 9 <revision pkgversion="3.12" date="2014-06-17" status="review"/> 10 11 <credit type="author copyright"> 12 <name>Petr Kovar</name> 13 <email>pknbe@volny.cz</email> 14 <years>2014</years> 15 </credit> 16 17 <include href="legal.xml" xmlns="http://www.w3.org/2001/XInclude"/> 18 19 <desc>Create a MIME type specification and register a default 20 application.</desc> 21 </info> 22 23 <title>Add a custom MIME type for all users</title> 24 <p> 25 To add a custom MIME type for all users on the system and register a default 26 application for that MIME type, you need to create a new MIME type 27 specification file in the <file>/usr/share/mime/packages/</file> 28 directory and a <file>.desktop</file> file in the 29 <file>/usr/share/applications/</file> directory. 30 </p> 31 <steps> 32 <title>Add a custom <sys>application/x-newtype</sys> 33 MIME Type for All Users</title> 34 <item> 35 <p> 36 Create the <file>/usr/share/mime/packages/application-x-newtype.xml</file> 37 file: 38 </p> 39 <code mime="application/xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?> 40<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> 41 <mime-type type="application/x-newtype"> 42 <comment>new mime type</comment> 43 <glob pattern="*.xyz"/> 44 </mime-type> 45</mime-info>]]></code> 46 <p> 47 The sample <file>application-x-newtype.xml</file> file above 48 defines a new MIME type <sys>application/x-newtype</sys> 49 and assigns file names with the <file>.xyz</file> extension to 50 that MIME type. 51 </p> 52 </item> 53 <item> 54 <p> 55 Create a new <file>.desktop</file> file named, for example, 56 <file>myapplication1.desktop</file>, and place it in the 57 <file>/usr/share/applications/</file> directory: 58 </p> 59 <code>[Desktop Entry] 60Type=Application 61MimeType=application/x-newtype 62Name=<var>My Application 1</var> 63Exec=<var>myapplication1</var></code> 64 <p> 65 The sample <file>myapplication1.desktop</file> file above 66 associates the <sys>application/x-newtype</sys> MIME type 67 with an application named <app>My Application 1</app>, 68 which is run by a command <cmd>myapplication1</cmd>. 69 </p> 70 </item> 71 <item> 72 <p>As root, update the MIME database for your changes to take effect:</p> 73 <screen><output># </output><input>update-mime-database /usr/share/mime</input> 74 </screen> 75 </item> 76 <item> 77 <p>As root, update the application database:</p> 78 <screen><output># </output><input>update-desktop-database /usr/share/applications</input> 79 </screen> 80 </item> 81 <item> 82 <p> 83 To verify that you have successfully associated 84 <file>*.xyz</file> files with the 85 <sys>application/x-newtype</sys> MIME type, first create 86 an empty file, for example <file>test.xyz</file>: 87 </p> 88 <screen><output>$ </output><input>touch test.xyz</input></screen> 89 <p> 90 Then run the <cmd>gio info</cmd> command: 91 </p> 92 <screen><output>$ </output><input>gio info test.xyz | grep "standard::content-type"</input> 93 standard::content-type: application/x-newtype</screen> 94 </item> 95 <item> 96 <p> 97 To verify that <file>myapplication1.desktop</file> has been 98 correctly set as the default registered application for the 99 <sys>application/x-newtype</sys> MIME type, run the 100 <cmd>gio mime</cmd> command: 101 </p> 102 <screen><output>$ </output><input>gio mime application/x-newtype</input> 103Default application for “application/x-newtype”: myapplication1.desktop 104Registered applications: 105 myapplication1.desktop 106Recommended applications: 107 myapplication1.desktop</screen> 108 </item> 109 </steps> 110</page> 111 112