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?

Eliah Kagan
  • 119,640
BevA
  • 847

11 Answers11

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.

Chan-Ho Suh
  • 7,582
  • 4
  • 43
  • 74
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....

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

2

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

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

Mariuz
  • 235
  • 2
  • 7
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"
Braiam
  • 69,112
Tom
  • 11
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.

uvasal
  • 513
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/

BevA
  • 847
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
brillout
  • 1,414
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!

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