I don’t often Torrent, but when I do, it’s my business and no one else’s. So, this is a quick write up for how to pause your torrents if your VPN goes down.
We’ll be using:
- MacOS née OS X
- Transmission - A multi-platform bittorrent client
- Homebrew The missing package manager for macOS
- and the Viscosity VPN client (if your VPN client can run scripts, it will work too.)
First things first. I’m assuming you’ve already installed transmission, if not. Go here and install it.
Next, because the transmission developers refuse to bundle the transmission command line interface (cli) with the MacOS build, we’ll need to install them via brew. If you don’t have brew yet for MacOS and are coming from a *nix background, you’ll be happy the I’m making you install it!
Then install the transmission client via brew (don’t worry, this only installs the command line utilities, not the application) by opening the terminal and running:
brew install transmission client
If necessary configure the transmission client to work with your installation. If you didn’t change any defaults, it should just work. Running:
is a good test to verify that the script is talking to transmission properly.
Now launch the AppleScript Editor.
- Click “New Document” in the bottom left corner of the file menu.
- Type do shell script “/usr/local/bin/transmission-remote -t all -s”
- Save the script as “start-transmission” somewhere that you’ll be able to find it again.
- Click File New
- Type do shell script “/usr/local/bin/transmission-remote -t all -S”
- Note the uppercase S
- Save the script as “stop-transmission”
If you’d like, you can test the scripts by clicking the icon. If you do this in the “start-transmission” script, the torrents should all start. I wonder if you can guess what the stop-transmission script does? :)
Now open viscosity.
- Click on your VPN connection
- Click the edit button
- Click to the advanced tab
- Click on the “Connected Script” and find the start-transmission script.
- Click on the “Disconnected Script” and find the stop-transmission script.
- Click Save
That’s it! At this point, if you disconnect the VPN, all transmission torrents should stop. If you start the VPN again, they should all start again.