Difference between revisions of "Custom File Associations"

From ArchWiki
Jump to: navigation, search
m
(added merge suggestion)
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
[[Category:Desktop environments]]
 +
 +
{{Merge|Default Applications|add contents of this page to the newer article}}
 +
 
The following method creates a custom mime type and file association manually.  This is useful if your desktop does not have a mime type/file association editor installed.  In this example, a fictional multimedia application 'foobar' will be associated with all '*.foo' files.  This will be done a per user basis (as opposed to system-wide).
 
The following method creates a custom mime type and file association manually.  This is useful if your desktop does not have a mime type/file association editor installed.  In this example, a fictional multimedia application 'foobar' will be associated with all '*.foo' files.  This will be done a per user basis (as opposed to system-wide).
  
* First, create the file {{Filename|~/.local/share/mime/packages/application-x-foobar.xml}}:
+
* First, create the file {{ic|~/.local/share/mime/packages/application-x-foobar.xml}}:
  
 
  $ mkdir -p ~/.local/share/mime/packages
 
  $ mkdir -p ~/.local/share/mime/packages
Line 7: Line 11:
 
  $ touch application-x-foobar.xml
 
  $ touch application-x-foobar.xml
  
* Then edit {{Filename|~/.local/share/mime/packages/application-x-foobar.xml}} and add this text:
+
* Then edit {{ic|~/.local/share/mime/packages/application-x-foobar.xml}} and add this text:
 
+
<pre>
<?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">
<mime-type type="application/x-foobar">
+
<mime-type type="application/x-foobar">
<comment>foo file</comment>
+
<comment>foo file</comment>
<icon name="application-x-foobar"/>
+
<icon name="application-x-foobar"/>
<glob-deleteall/>
+
<glob-deleteall/>
<glob pattern="*.foo"/>
+
<glob pattern="*.foo"/>
</mime-type>
+
</mime-type>
</mime-info>
+
</mime-info>
 
+
</pre>
 
Note that you can use any icon, including one for another application.
 
Note that you can use any icon, including one for another application.
  
* Next, edit or create the file {{Filename|~/.local/share/applications/foobar.desktop}} to contain something like:
+
* Next, edit or create the file {{ic|~/.local/share/applications/foobar.desktop}} to contain something like:
  
 
  [Desktop Entry]
 
  [Desktop Entry]
Line 40: Line 44:
  
 
Programs that use mime types, such as file managers, should now open '*.foo' files with foobar.  (You may need to restart your file manager to see the change.)
 
Programs that use mime types, such as file managers, should now open '*.foo' files with foobar.  (You may need to restart your file manager to see the change.)
 
[[Category: HOWTOs (English)]]
 

Revision as of 07:21, 9 June 2012


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

Notes: add contents of this page to the newer article (Discuss in Talk:Custom File Associations#)

The following method creates a custom mime type and file association manually. This is useful if your desktop does not have a mime type/file association editor installed. In this example, a fictional multimedia application 'foobar' will be associated with all '*.foo' files. This will be done a per user basis (as opposed to system-wide).

  • First, create the file ~/.local/share/mime/packages/application-x-foobar.xml:
$ mkdir -p ~/.local/share/mime/packages
$ cd ~/.local/share/mime/packages
$ touch application-x-foobar.xml
  • Then edit ~/.local/share/mime/packages/application-x-foobar.xml and add this text:
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
	<mime-type type="application/x-foobar">
		<comment>foo file</comment>
		<icon name="application-x-foobar"/>
		<glob-deleteall/>
		<glob pattern="*.foo"/>
	</mime-type>
</mime-info>

Note that you can use any icon, including one for another application.

  • Next, edit or create the file ~/.local/share/applications/foobar.desktop to contain something like:
[Desktop Entry]
Name=Foobar
Exec=/usr/bin/foobar
MimeType=application/x-foobar
Icon=foobar
Terminal=false
Type=Application
Categories=AudioVideo;Player;Video;
Comment=

Note that Categories should be set appropriately for the application type (in this example, a multimedia app).

  • Now update the mime database with:
$ update-mime-database ~/.local/share/mime

Programs that use mime types, such as file managers, should now open '*.foo' files with foobar. (You may need to restart your file manager to see the change.)