Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
mimetypes [2015/07/13 00:57]
slackermedia
mimetypes [2021/06/03 19:48] (current)
Line 1: Line 1:
-[[{arrowp.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​position:​absolute;​top:​0;​left:​0;​}dotdesktop|]] 
  
-[[{arrown.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​position:​absolute;​top:​0;​margin-left:​2.5em;​}path|]] 
  
 ======MIMEtypes====== ======MIMEtypes======
Line 32: Line 30:
 =====Custom MIMEtypes===== =====Custom MIMEtypes=====
  
 +The time that the easy method of setting MIME prefernces falters is when you want to define action for an arbitrary suffix. For instance, if you use Emacs org-mode for your daily agenda, then you might want any file ending in ''​.org''​ to open in Emacs, or if you write your screenplays in [[fountain|.fountain]] markdown and want all files ending in ''​.fountain''​ to open in Kate. To your computer, these suffixes are meaningless,​ so it defaults to a quick filetype check and opens whatever application is the most logical.
  
-create ​MIMEtype schema +Try it yourself with file meant for [[screenwriter|Screenwriter-mode]]:​ 
-mime-scp.xml+ 
 +<​code>​ 
 +$ echo "INT. HOUSE NIGHT" >> ~/example.scp 
 +$ file ~/example.scp 
 +/​home/​klaatu/​example.scp:​ ASCII text 
 +</​code>​ 
 + 
 +Of course, the computer is right; the file //is// ASCII text, but that doesn'​t change the fact that you want it to open in a specific application. You could try the easy method, telling KDE to always open ''​.scp''​ files in Emacs, but ''​.scp''​ is not a MIMEtype, it's just a set of random characters at the end of a filename. Telling KDE to open all files like ''​example.scp''​ is really just telling KDE to open all plain text files with a specific application,​ and that is not what you want. You want to filter out all ''​.scp''​ files away from other plain text files. and do something unique. 
 + 
 +To do this, you must define your own MIMEtype.  
 + 
 +MIMEtypes can be defined in 7 lines of XML. Here is a specification for a ''​.scp''​ file, which will open in Emacs:
  
 <​code>​ <​code>​
 <?xml version="​1.0"?>​ <?xml version="​1.0"?>​
-<​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-scp">​ +      <​mime-type type="​application/​x-scp">​ 
-<​comment>​Emacs Screenwriter File</​comment>​ +      <​comment>​Emacs Screenwriter File</​comment>​ 
-<glob pattern="​*.scp"/>​ +      <glob pattern="​*.scp"/>​ 
-</​mime-type>​+   ​</​mime-type>​
 </​mime-info>​ </​mime-info>​
 </​code>​ </​code>​
  
 +Save that file as ''​mime-scp.xml''​ and install it to your system'​s MIMEtype database:
 +
 +<​code>​
 $ xdg-mime install mime-scp.xml $ xdg-mime install mime-scp.xml
 +</​code>​
  
- What Klaatu fails to mention is the way to programmatically give the MIMEtype ​that you create ​an icon. The secret ​is to name your icon the same thing as your mimetype ​xml file, with dashes instead of slashes ​(for example, application-text-scp.svg) and place the icon file in the appropriate category in /​usr/​share/​icons/​hicolor/​scalable+You may have to log out and log back in (it should be enough just to close any running instance of Dolphin), but now the MIMEtype is active within your user's login. Right-click on a ''​.scp''​ file and set files of its type to open in Emacs. Be sure to place a tick in the **Remember** checkbox. 
 + 
 +From now on, any file ending in ''​.scp''​ will open in Emacs, but all other plain text files will continue to default to their usual settings. 
 + 
 +====Custom Icons==== 
 + 
 +You can set a custom icon for your MIMEtype, too. Create or choose ​an icon (either a PNG or SVG is valid) and name your icon the same thing as the ''​mime-type type''​ line in your custom ​mimetype ​XML spec, with dashes instead of slashes, and move it to the master icon repository ​for your system (''/​usr/​share/​icons/​hicolor/''​). Continuing with the ''​.scp'' ​example
 + 
 +<​code>​ 
 +$ grep mime-type mime-scp.xml | cut -f2 -d'"'​ 
 +application/​x-scp 
 +$ su -c 'mv myFancyIcon.svg /​usr/​share/​icons/​hicolor/​scalable/​application-x-scp.svg'​ 
 +</​code>​
  
-You may have to log out and log back in for things to kick in, but it works a treat.+You may have to log out and log back in for things to kick in, but this will assign all ''​.scp''​ files your chosen icon, and those files will open in whatever application you choose in KDE.
  
  
 +<WRAP centeralign>​
 +<wrap fa>​[[drives|R]]</​wrap>​ <wrap fa>​[[start|S]]</​wrap>​ <wrap fa>​[[path|Q]]</​wrap>​
 +</​WRAP>​
  
-[[{arrown.png|border:​0;​background:​none;​width:​0;​display:​inline-block;​float:​right;​}path|]][[{arrowp.png|border:​0;​background:​none;​width:​0;​float:​right;​}dotdesktop|]]