AppleScript: Automatically Quit/Pause Transmission when using Viscosity VPN Client

This article explains how to use some AppleScript to quit/pause the Transmission BitTorrent client when you connect to your VPN through Viscosity and reopen/resume it when you disconnect. Very useful if your VPN provider has a policy of disabling your account for BitTorrent usage….

Being based in China, I rely on a VPN service to access the numerous blocked sites that the Chinese Government deem undesirable – Facebook, YouTube, Twitter etc. Essentially if its popular in the west, it’ll be blocked here.

My current VPN provider, the excellent 12VPN, have recently begun enforcing their restrictions on the use of Torrent traffic over the VPN. While I wouldn’t intentionally use Transmission over the VPN, it is easy to forget to disable Transmission when connecting, resulting in my account being temporarily disabled. I understand the position of 12VPN but it is irritating none the less.

I therefore decided to find a way to prevent this from happening using the power of AppleScript. I have two solutions to the problem, the first will simply pause Transmission downloads while you are connected. The second will quit Transmission entirely. Choose whichever solution you prefer.

To install, save the scripts you want from below and follow the instructions here.

Essentially, under the Advanced tab of the VPN connection, you need to select the ‘TransmissionPause’ file OR ‘TransmissionQuit’ file as the ‘Before Connect Script’, and select the ‘TransmissionResume’ file OR ‘TransmissionReopen’ file as ‘Disconnected Script’. That’s it!

Note 1 – If you are using the Quit/Reopen solution, make sure to untick ‘Prompt for: Quit with active transfers’ in the Transmission preferences. This will ensure Transmission quits automatically without showing a ‘Are you sure?’ prompt.

Note 2 – You can also download all these scripts as a Zip file here.

(Hat tip to user Minckster at the Shirt Pocket forums for the code base.)

AppleScripts to Pause/Resume Transmission

Open ‘Applescript Editor’ App on your Mac and save this code to a file called ‘TransmissionPause’:

-- Pause Transmission, if running
tell application "System Events"
if ((count (every process whose name is "Transmission")) > 0) then
tell application "Transmission" to activate
tell application "System Events"
tell process "Transmission"
-- Pause all downloads in Transmission
keystroke "." using {option down, command down}
end tell
end tell
end if
end tell

Open ‘Applescript Editor’ App on your Mac and save this code to a file called ‘TransmissionResume’:

-- Resume Transmission, if running
tell application "System Events"
if ((count (every process whose name is "Transmission")) > 0) then
tell application "Transmission" to activate
tell application "System Events"
tell process "Transmission"
-- Resume all downloads in Transmission
keystroke "/" using {option down, command down}
end tell
end tell
end if
end tell

AppleScripts to Quit/Reopen Transmission

Open ‘Applescript Editor’ App on your Mac and save this code to a file called ‘TransmissionQuit’:

-- Quit Transmission, if running
tell application "System Events"
if ((count (every process whose name is "Transmission")) > 0) then
tell application "Transmission"
-- Quit Transmission
quit
end tell
end if
end tell

Open ‘Applescript Editor’ App on your Mac and save this code to a file called ‘TransmissionReopen’:

-- Open Transmission, if closed
tell application "System Events"
if ((count (every process whose name is "Transmission")) = 0) then
tell application "Transmission" to activate
end if
end tell


 

  • Keith Robinson

    I use one very similar but I route my torrent traffic via a block of ports I do not pass via VPN …