Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Right now Chrome throws its apron over its head and calls Firefox, which opens the link with rtorrent. What do I need to do to eliminate the Firefox step?

share|improve this question
    
what version of Google chrome are you running? google-chrome -version –  Alvar May 8 '12 at 8:14

9 Answers 9

Chrome (or Chromium) protocol handling works differently than in Firefox. Firefox basically keeps track of all that itself, which is why you can configure protocol handling (like magnet links) in the Applications part of the Preferences. Chrome, however, relies on xdg-open.

There are a couple things that you need to do before xdg-open will handle magnet links properly.

  1. Find the name of the desktop file of the program you want to handle the magnet link. Let's suppose the program is Transmission. It (like usual) has its desktop file in /usr/share/applications/ and in fact, by perusing the listing of the directory, I find that my version of transmission is actually the gtk version, so its desktop file is called transmission-gtk.desktop.

  2. It's possible the desktop file is messed up. So you can check that /usr/share/applications/transmission-gtk.desktop contains the lines:

    Exec=transmission-gtk %U
    [some lines omitted]
    MimeType=application/x-bittorrent;x-scheme-handler/magnet;
    

    Note the %U in the Exec line. It's absolutely necessary. The MimeType line should look as above.

  3. Now for the essential step to tell xdg-open to open magnet links using Transmission. In the terminal, type:

    xdg-mime default transmission-gtk.desktop x-scheme-handler/magnet 
    
  4. (Step not necessary if you use Gnome, KDE, Xfce, or LXDE) Lastly, xdg-open assumes you are running one of the standard desktop environments: gnome, kde, xfce and lxde. If you are not, xdg-open will not work on magnet links. As suggested on the Arch wiki, you can simply modify /usr/bin/xdg-open. At the end of the file, you'll find a portion that starts with:

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

    change generic to one of gnome, kde, xfce, or lxde. I chose xfce since I actually have an Xfce session that I've configured and use on occasion.

    The downside to this approach is that if xdg-open gets updates, you'll have to redo this. The Arch wiki suggests another approach that avoids this flaw (but has its own downside).

    Warning: The choice in the last step is more important than it might seem. Picking lxde did not work for me! In xdg-open, the helper function open_lxde relies on pcmanfm (lxde file manager) and something is wrong with either the code in open_lxde or perhaps it's pcmanfm's fault.

share|improve this answer
    
Worked like a charm. Thanks! –  Diego Agulló Nov 8 '12 at 20:18
3  
Thank you! I just did a xdg-mime default deluge.desktop x-scheme-handler/magnet to associate it with Deluge instead. –  sidewaysmilk Jan 1 '13 at 5:34
1  
I'm having a (probably) related problem. I've tried your solution but it's not working. –  Quinn Culver Jul 13 '13 at 15:46
2  
Also wanted to say thanks for the answer, it worked great. Since I'm on Linux Mint using MATE instead of GNOME, I had to do step 4. Strangely, mate didn't work (which I would have expected since I run MATE), but gnome did. –  machineghost Jan 18 at 20:16
1  
@machineghost thanks for your comment: i'm on MATE too and this answer + your comment sorted it for me. –  Max Williams Apr 7 at 10:04

just drag the magnet link into Transmission window and it works fine for me without any tweaks.... I am using a stock build of Lubuntu 12.10 nothing fancy....

share|improve this answer
    
This is another approach and I like it. But it doesn't solve the issue when the magnet link is opened automatically and it requires much user interaction (clicks) when transmission isn't already running. –  Joel Sjögren Jul 22 '13 at 8:11

A guy in alt.os.linux.slackware found the solution:

http://www.void.gr/kargig/blog/2012/01/24/open-magnet-urls-with-xdg-open/

share|improve this answer
    
Welcome to Ask Ubuntu! While this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  michaelms Mar 2 '12 at 3:10
    
This is actually more complicated than needed. See my answer. –  Chan-Ho Suh May 8 '12 at 8:09

if you use xfce and don't want to mess anything, you could use my solution. I fixed by manually editing xdg-open as follows:

First of all make sure you have the mime associated (as explained before, with xdg-mime)

Then backup xdg-open as root (sudo if that applies)

# cp /usr/bin/xdg-open /usr/bin/xdg-open.old

Finally, edit as root /usr/bin/xdg-open, find open_xfce() and add the lines marked with +, e.g., with nano

# nano /usr/bin/xdg-open

open_xfce()
+ if [ "\`echo $1 | sed -n 's/\(^[[:alnum:]+\.-]*\):.*$/\1/p'\`" == "magnet" ]; then
+     gnome-open "$1"
+ else
      exo-open "$1"
+ fi

it only adds the exception for the magnet links, so they will be opened with gnome-open instead of exo-open.

Hope it helps.

share|improve this answer

Worked very nice to open magnets from Chrome with qBitorrent in Lubuntu

xdg-mime default qBittorrent.desktop x-scheme-handler/magnet

share|improve this answer

None of the other suggestions I found worked for me, but this did the trick under Debian / Xfce ( from http://fluxcode.net/archives/57 ):

In /usr/bin/xdg-open add the following lines to open_xfce()

open_xfce()
{
 if(echo "$1" | grep -q '^magnet:'); then
    transmission-gtk "$1" 
    if [ $? -eq 0 ]; then
       exit_success
    fi
 fi

exo-open "$1"
share|improve this answer

Using gnome-open on XFCE worked out for me.

This can be forced with editing /usr/bin/xdg-open and change

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

to

if [ x"$DE" = x"" ]; then
  DE=generic
fi
DE=gnome
share|improve this answer

I mixed few answers (that unfortunately didn't work for me) and came up with something that made it work like a charm! It worked on Linux Mint 16 under XFCE, anyways.

Make backup of xdg-open under /usr/bin, open your xdg-open with sudo and then make open_xfce() function exactly like this:

open_xfce()
{    
    if (echo "$1" | grep -q '^magnet:'); then
        gnome-open "$1"
    else
        exo-open "$1"
    fi
}

It's dirty and you need to edit it every xdg-open update, but hey, it works!

share|improve this answer

I've tried for years to fix this and switch to Chrome and nothing seems to work. I finally had a thought I'm not sure why I didn't think of before and it works great. I'm using Tixati in Mint but it should work universally. Chrome points magnet links to usr/bin/transmission-gtk so I renamed that to transmission-gtk.old and renamed tixati to transmission-gtk and picked the option in chrome to always do this and hit launch app and now mag links go straight into Tixati just like Firefox. Problem finally solved!

share|improve this answer

protected by Community Sep 1 at 8:47

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.