Fixing uTorrent File Associations in Linux
Running uTorrent under wine works pretty well in Linux. For a quick overview of installation, see this HowTo Ubuntu blog post. One problem with installing under wine is that file associations are not set correctly. This means that double-clicking a .torrent file or opening a .torrent link in your browser won’t automatically start uTorrent. Here’s how to solve that.
First, create a file called utorrent with the following content:
#!/bin/sh
if [ "$1" ]; then
torrent_file="Z:`echo $1 | sed 's/\//\\\/g'`"
env WINEPREFIX="/home/avery/.wine" wine \
"C:\\Program Files\\uTorrent\\uTorrent.exe" "$torrent_file"
else
env WINEPREFIX="/home/avery/.wine" wine \
"C:\\Program Files\\uTorrent\\uTorrent.exe"
fi
Replace /home/avery with the path to your home directory. Make sure to make the file executable:
$ chmod +x utorrent
This is the main script that we’ll start uTorrent with. Basically, if given a file path on the command line, it will transform it from a linux path to a wine path. /tmp/sample.torrent will become Z:\tmp\sample.torrent. The sed bit comes from an Ubuntu forums thread.
Next, we need to fix the .desktop file. It should be located at ~/.local/share/applications/wine/µTorrent.desktop and contain something like:
[Desktop Entry]
Name=µTorrent
Exec=env WINEPREFIX="/home/avery/.wine" wine \
"C:\\Program Files\\uTorrent\\uTorrent.exe"
Type=Application
StartupWMClass=Wine
Icon=6948_utorrent.0
Add the following two lines to the end of the file:
Categories=Network;FileTransfer;P2P MimeType=application/x-bittorrent
The first line makes uTorrent show up correctly in the GNOME menu system. The next associates uTorrent with the BitTorrent MIME type. Also, change the Exec line to:
Exec=/home/avery/bin/utorrent %f
Obviously, replace the path with wherever you put the utorrent script from above. The .desktop file should now contain:
[Desktop Entry] Name=µTorrent Exec=/home/avery/bin/utorrent %f Type=Application StartupWMClass=Wine Icon=6948_utorrent.0 Categories=Network;FileTransfer;P2P MimeType=application/x-bittorrent
To make uTorrent the default BitTorrent client, edit ~/.local/share/applications/defaults.list:
[Default Applications] application/x-bittorrent=µTorrent.desktop
This file might already exist, in which case you can just add the second line. Finally, we need to update GNOME’s file associations database:
$ update-desktop-database ~/.local/share/applications
Success: