- Create or edit a .desktop file in /usr/share/applications that looks like this (note lines 6 and 13):
1234578910111214[Desktop Entry]Encoding=UTF-8Version=1.0Type=ApplicationTerminal=falseName[en_US]=TunesViewerComment[en_US]=Small, easy-to-use program to access iTunesU mediaName=TunesViewerComment=Small, easy-to-use program to access iTunesU mediaIcon=/usr/share/icons/hicolor/scalable/apps/tunesview.svgCategories=Application;Network;Comment[en_US.utf8]=Small, easy-to-use program to access iTunesU media
- Run the following command:
1$ sudo update-desktop-database
For a bit of an explanation, keep reading.
If you’re like me, you sometimes stumble across a strange system administration problem that you solve by hacking together a solution that you don’t know why it works. This happens all the time. Yes, negligence or laziness can be the culprit, but sometimes what you did is so obscure or esoteric that its simply not cost-effective to spend the time researching the reasons it works. That latter scenario can often be blamed on a case of poor documentation.
In my case, it was a case of poor documentation of a recent change in system policy and a lack of uptake in the blogosphere in figuring it out.
The goal was simple: I needed a way to browse iTunes Store links in Linux (specifically, Ubuntu). The immediate solution I found was also simple: install TunesViewer (version 1.2 at the time). The first computer I tried this on it worked, however when it was tried it on a second computer iTunes Store links would not automatically launch TunesViewer from any web browser. Thus began my digging.
The first relevant thing I found was this bug report about Google Chrome. It reflected my situation exactly, as the main difference between the first and second computers was that the first computer was running Ubuntu 10.10 while the second computer was running Ubuntu 11.04. Unfortunately, it also derailed my search into looking up information on how to use gconftool-2  and various programs/scripts to auto-detect file associations . This did not end up leading me to a solution. However, I eventually found a forum post which lead me to this Ubuntu bug report, which informed me of another mechanism by which I could specify file associations: Desktop Entry files.
When supported by the user’s environment, a Desktop Entry file allows programs to provide various bits of metadata to the environment regarding its execution and presentation. Among other things, you can specify a program icon, name and comments in multiple languages, the command used to launch the program, and (of most importance to me) specify MIME types that the program knows how to deal with.
Ubuntu keeps these Desktop Entry files in various places, but the primary location is
/usr/share/applications. Thankfully, TunesViewer (still 1.2) came in a .deb package with a Desktop Entry file included, so it was a simple matter to edit in the necessary changes. The code below highlights the changes needed, namely lines 6 and 13:
Comment[en_US]=Small, easy-to-use program to access iTunesU media
Comment=Small, easy-to-use program to access iTunesU media
Comment[en_US.utf8]=Small, easy-to-use program to access iTunesU media
The changes to line 6 were minimal: I just had to make sure “%U” was there, as that tells the user environment that the application can take multiple URLs (which TunesViewer can). Line 13 was added new. The
MimeType key takes as its value one or more semicolon-delimited MIME types. In my case I was interested in associating TunesViewer with iTunes Store URLs, which use their own protocol identifiers, so I had to specify MIME types for those protocols:
itms:// -> x-schema-handler/itms
itmss:// -> x-schema-handler/itmss
itpc:// -> x-schema-handler/itpc
Now, it would be a relatively slow operation if every time a user wanted to open a file the system had to search through individual Desktop Entry files until it found a matching MIME type. To aid in this, the system generates a file that acts as a MIME type cache. This file lists all the known MIME types that have program associations along with the Desktop Entry files in which they appear. In Ubuntu, at least, this file is
/usr/share/applications/mimeinfo.cache. As such, once a change is made to a Desktop Entry file, the following command must be run for any changes in MIME type associations to take effect:
$ sudo update-desktop-database
Voila! It worked. But something still nagged at me: …why did I need to do this in the first place?
The answer to that question came to me in the form of a software update. A few days after I had solved the problem, TunesViewer released its version 1.3. Among other things, it addressed the compatibility issues it had with Ubuntu 11.04. Even better, included in the version notes was an explanation as to why they had to make the change. It turned out to be because of Ubuntu’s choice to go with GNOME 3.0 as the backend for its default user environment for 11.04, whereas in prior versions they used GNOME 2.x. With the release of version 3.0, GNOME decided to switch its default URL handling scheme from using GConf to using MIME types in Desktop Entry files. Now, while they had understandable and perhaps even good reason for doing this, a year thence there has been almost no coverage on it and there’s still some work to be done on the GNOME project to bring it in-line with the proposed change. There may be other applications that still need to make the transition as well.
-  Desktop Entry Specification (Latest) ↩
-  GConf Configuration System ↩
-  Re: how to add a uri protocol handler? (i.e. irc://) – ubuntuforums.org ↩
-  Using gnome-open to open pdf files – askubuntu.com ↩
-  xdg-open vs exo-open – teranex weblog ↩
-  MIME – Wikipedia ↩
-  deb (file format) – Wikipedia ↩
-  Definition of Protocol Identifier – eHow.com ↩