Difference between revisions of "Changing filetype association via MIME"

From ArchWiki
Jump to: navigation, search
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
Many of you will be wanting to run windows apps within your linux installation, and you can do this via the wonderful [[Wine]]. This guide will show you how to alter your MIME database in a safe way so that you can associate windows executables with Wine.
+
[[Category:Wine]]
 +
[[ru:Changing filetype association via MIME]]
 +
{{Merge|Default Applications|add content of this page to the newer article}}
 +
 
 +
Many of you will be wanting to run Windows applications within your Linux installation, and you can do this via the wonderful [[Wine]]. This guide will show you how to alter your MIME database in a safe way so that you can associate Windows executables with Wine.
 
'''Warning''': Do NOT attempt to modify the mime database directly!
 
'''Warning''': Do NOT attempt to modify the mime database directly!
  
 
+
First, create the file {{ic|~/.local/share/mime/packages/mime.xml}} as such:
* First, create the file "~/.local/share/mime/packages/mime.xml", as such:
+
 
+
 
+
 
  $ mkdir -p ~/.local/share/mime/packages
 
  $ mkdir -p ~/.local/share/mime/packages
  $ cd ~/.local/share/mime/packages
+
  $ touch ~/.local/share/mime/packages/mime.xml
$ touch mime.xml
+
(Or you can just do it with your graphical file browser)
+
 
+
 
+
* Next, open up mime.xml and paste the following inside:
+
 
+
  
 +
Next, open up {{ic|mime.xml}} and paste the following inside:
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
 
  <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
Line 23: Line 19:
 
  </mime-info>
 
  </mime-info>
  
 
+
Finally, enter this at the command prompt:
* Finally, enter this at the command prompt:
+
 
+
 
+
 
  $ update-mime-database ~/.local/share/mime
 
  $ update-mime-database ~/.local/share/mime
 
  
 
That's it!
 
That's it!
  
The method outlined above will intergrate the xml file you made with the mime database, so that you can make your own associations for .exe files (probably [[Wine]]).
+
The method outlined above will integrate the xml file you made with the mime database, so that you can make your own associations for .exe files (probably [[Wine]]).
  
 
==Setting mime handler for arbitrary files==
 
==Setting mime handler for arbitrary files==
Line 38: Line 30:
  
 
The mime type somehow is in the file so it is not the app that says "use mime type x on this file" but it's rather "use whatever mime type is associated with this file". To see a mime type of a file called test.mp4 use this command:
 
The mime type somehow is in the file so it is not the app that says "use mime type x on this file" but it's rather "use whatever mime type is associated with this file". To see a mime type of a file called test.mp4 use this command:
 
+
$ xdg-mime query filetype test.mp4
<pre>$ xdg-mime query filetype test.mp4</pre>
+
  
 
In my example I got this:
 
In my example I got this:
 
+
audio/mp4; charset=binary
<pre>audio/mp4; charset=binary</pre>
+
  
 
Now we set the mime-type, in my example I want to use rox to handle this file, and then configure rox to use vlc:
 
Now we set the mime-type, in my example I want to use rox to handle this file, and then configure rox to use vlc:
 
+
$ xdg-mime default rox.desktop audio/mp4
<pre>$ xdg-mime default rox.desktop audio/mp4</pre>
+
  
 
Since I already set the default action for that file in rox with a right-click and then using "vlc" as the command, this now works beautifully.
 
Since I already set the default action for that file in rox with a right-click and then using "vlc" as the command, this now works beautifully.
  
 
If you are wondering, setting the default app for a mime type will edit the file
 
If you are wondering, setting the default app for a mime type will edit the file
<pre>~/.local/share/applications/defaults.list</pre>
+
  ~/.local/share/applications/defaults.list
  
 
and add the following for this magic to work:
 
and add the following for this magic to work:
<pre>
+
<Default Applications>
<Default Applications>
+
audio/mp4=rox.desktop
audio/mp4=rox.desktop
+
</pre>
+
 
+
On a side note, does anyone else feel that freedesktop.org's documentation really blows? Isn't all of the above supposed to be explained for example here? <url>http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec</url>
+
  
[[Category: HOWTOs (English)]]
+
== Resources ==
[[Category: Wine (English)]]
+
* http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec

Revision as of 10:42, 13 June 2012

Merge-arrows-2.pngThis article or section is a candidate for merging with Default Applications.Merge-arrows-2.png

Notes: add content of this page to the newer article (Discuss in Talk:Changing filetype association via MIME#)

Many of you will be wanting to run Windows applications within your Linux installation, and you can do this via the wonderful Wine. This guide will show you how to alter your MIME database in a safe way so that you can associate Windows executables with Wine. Warning: Do NOT attempt to modify the mime database directly!

First, create the file ~/.local/share/mime/packages/mime.xml as such:

$ mkdir -p ~/.local/share/mime/packages
$ touch ~/.local/share/mime/packages/mime.xml

Next, open up mime.xml and paste the following inside:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
  <mime-type type="application/x-ms-dos-executable">
         <comment xml:lang="en">Windows Executable</comment>
         <glob pattern="*.exe"/>
  </mime-type>
</mime-info>

Finally, enter this at the command prompt:

$ update-mime-database ~/.local/share/mime

That's it!

The method outlined above will integrate the xml file you made with the mime database, so that you can make your own associations for .exe files (probably Wine).

Setting mime handler for arbitrary files

In this example, we are going to define rox as the file handler of a file called "test.mp4".

The mime type somehow is in the file so it is not the app that says "use mime type x on this file" but it's rather "use whatever mime type is associated with this file". To see a mime type of a file called test.mp4 use this command:

$ xdg-mime query filetype test.mp4

In my example I got this:

audio/mp4; charset=binary

Now we set the mime-type, in my example I want to use rox to handle this file, and then configure rox to use vlc:

$ xdg-mime default rox.desktop audio/mp4

Since I already set the default action for that file in rox with a right-click and then using "vlc" as the command, this now works beautifully.

If you are wondering, setting the default app for a mime type will edit the file

 ~/.local/share/applications/defaults.list

and add the following for this magic to work:

<Default Applications>
audio/mp4=rox.desktop

Resources