Saturday, November 16, 2013

Linux Mint - Mate Desktop: Configure transmission-gtk to handle magnet-links in Google Chrome

Objective


The goal of this tutorial is to make Google Chrome to automatically to start transmission-gtk when you click on a magnet-link within your browser.

Motivation


I was using Firefox (and previously the Mozilla Suite) as my favorite Webbrowser for nearly everthing (on Linux, Window and Mac). Recently I experimented with Google Chrome and figured out that it's also a nice alternative to Firefox and in many cases much faster. But one of the drawbacks I encountered on Linux was, that it seems to handle foreign or unknown protocols differently than Firefox. It merely relies on "xdg-open", which is not always configured correctly, for any desktop environments, as in my case.

Prerequisites


Linux Mint 15 - Olivia
Desktop - MATE 1.6
Google Chrome (v31.0.1650.57)
transmission-gtk (v2.77-14031)
xdg-open (v1.0.2)

It might be that the problem occurs also with other Distributions and Versions, but the above is just my current environment.

Solution


Reproduce the problem


1. Start Google Chrome
2. Navigate to an internet site that provides a magnet-link
3. Click on the link
4. If Google Chrome opens just another window or tab, you face the problem

Solve the problem


In contrary to Firefox which handles all the management of external protocol-handlers itself, Google Chrome relies on the underlying system. In this particular environment it's the "xdg-open" script. Unfortunatelly this script does not support MATE a native Desktop environment and therefore calls the "general-handler" for urls which seems to be Google Chrome itself.

In this solution, we establish the external app "transmission-gtk" the to handle magnet-links within Google-Chrome.

1.
Check where the "transmission-gtk.desktop" file can be found. E.g. use the command "locate transmission-gtk.desktop". In my case it's located in "/usr/share/applications/".

2.
Now check the content, by opening the file with an editor of your choice. Be sure that you find the statements

Exec=transmission-gtk %U

and

MimeType=application/x-bittorrent;x-scheme-handler/magnet;

in the file. Ensure that the first statement contains "%U", because this the placeholder for the concrete URL passed through by Google Chrome.

3.
Configure your system that "transmission-gtk" is the default handler for magnet-links by executing the following command in your shell:

$ xdg-mime default transmission-gtk.desktop x-scheme-handler/magnet

4.
Enable "xdg-open" to recognize your MATE desktop as a Gnome Desktop, because it has the same ancestor and therefore is compatible to Gnome, but not recognized in the "xdg-open" script, because of the different name.

For this step you need root permission, so be careful what you are doing.
Locate the xdg-open script in your system: "which xdg-open". In my case this leads to "/usr/bin/xdg-open".
Open the file as root (again with your editor of choice) e.g. "sudo vi /usr/bin/xdg-open".
Search for a section (Note: The following part is just hack and not a solid solution):

if [ x"$DE" = x"" ]; then
    DE=generic
fi

and change it to

if [ x"$DE" = x"" ]; then
    DE=gnome
fi

Now, save the file.

5.
Restart Gnome and retry to reproduce the problem. It should be gone now and transmission-gtk should be opened to handle magnet-links instead of Google Chrome.