73

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?

2
  • what version of Google chrome are you running? google-chrome -version
    – Alvar
    May 8, 2012 at 8:14
  • This happened to me (on Ubuntu 14.04.2 LTS) when Firefox was set as my default browser. If Chromium was set as my default browser, then I only got a new empty tab in Chromium. -- In the end I solved the problem by patching my /usr/bin/xdg-open as suggested in the accepted answer to "Torrent magnet links open new window but not transmission".
    – zrajm
    May 31, 2015 at 13:54

11 Answers 11

92

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.

12
  • 7
    Thank you! I just did a xdg-mime default deluge.desktop x-scheme-handler/magnet to associate it with Deluge instead. Jan 1, 2013 at 5:34
  • 1
    I'm having a (probably) related problem. I've tried your solution but it's not working. Jul 13, 2013 at 15:46
  • 2
    How can Linux succeed, when experts let alone noobs can't make it work. I use Linux by preference every day, but the desktop experience is not good enough. Good luck to SteamOS. Nov 29, 2013 at 11:05
  • 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. Jan 18, 2014 at 20:16
  • 1
    @machineghost thanks for your comment: i'm on MATE too and this answer + your comment sorted it for me. Apr 7, 2014 at 10:04
8

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....

1
  • 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. Jul 22, 2013 at 8:11
2

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

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

2

In Ubuntu 20.04, run one of the following commands.

Webtorrent

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

Transmission

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

Any other torrent application

X.desktop file must exist in the /usr/share/applications directory

1

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.

1

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"
0

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/

2
  • 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. Mar 2, 2012 at 3:10
  • This is actually more complicated than needed. See my answer. May 8, 2012 at 8:09
0

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
0

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!

0

This works for me in ubuntu 18 with FF (for deluge):

gio mime x-scheme-handler/magnet deluge.desktop

I know that doesn't answer the question but I use Chrome too and this is a better work around than copying and pasting the magnet link.

-1

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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .