Hi Guys,
This simple applescript works - had lots of help from Camelot and another on applescript support forums:
Before you start go into terminal and type 'ifconfig -lu' do this with your VPN on and off - work out what interface is the VPN (mine is tun0), run ifconfig -lu again with VPN off, copy the result into the space " "
on idle
set activeInterfaces to do shell script "ifconfig -lu"
if activeInterfaces = "lo0 en0 fw0 en1 utun0" then
tell application "Transmission" to quit
end if
return 10 -- 30 is default value, but it doesn't hurt to include it here
end idle
cut and past this script into the applescript editor as a new script, save as an application and tick stay open.
Now run this every time you have your VPN and transmission on, within 10 seconds of the VPN dropping it will quit Transmission - you can change the timing to suit you.
I also have a version that gives me growl messages, but you will need to go through the growl app setup applescript that come with growl to register the app with growl.
on idle
set activeInterfaces to do shell script "ifconfig -lu"
if activeInterfaces = "lo0 en0 fw0 en1 utun0" then
tell application "Transmission" to quit
tell application "Growl"
notify with name ¬
"VPN Down" title ¬
"VPN Down" description ¬
"I have quit Transmission." application name "Drop BitTorrent"
end tell
end if
return 10 -- 30 is default value, but it doesn't hurt to include it here
end idle
Good luck.
Bind Transmission to Interface with Applescript
Re: Bind Transmission to Interface with Applescript
Awesome script. Works like a charm! I did change the "if ... is" part to "if ... is not", just because it feels a little safer. So activeInterfaces is ever anything else that doesn't have the VPN connection in it, it dies:
...
if activeInterfaces is not "lo0 en0 en1 p2p0 fw0 vnic0 vnic1 tap0" then
...
Also, here's how to register it with Growl, in case anyone is wondering. I added this part at the end of the script, ran it, then just deleted it. Now I know if openVPN ever dies:
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell
if isRunning then
tell application id "com.Growl.GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"VPN Down", "openVPN quit unexpectedly"}
-- Make a list of the notifications
set the enabledNotificationsList to ¬
{"VPN Down"}
-- Register our script with growl.
register as application ¬
"Drop BitTorrent" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Script Editor"
end tell
end if
...
if activeInterfaces is not "lo0 en0 en1 p2p0 fw0 vnic0 vnic1 tap0" then
...
Also, here's how to register it with Growl, in case anyone is wondering. I added this part at the end of the script, ran it, then just deleted it. Now I know if openVPN ever dies:
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell
if isRunning then
tell application id "com.Growl.GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"VPN Down", "openVPN quit unexpectedly"}
-- Make a list of the notifications
set the enabledNotificationsList to ¬
{"VPN Down"}
-- Register our script with growl.
register as application ¬
"Drop BitTorrent" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Script Editor"
end tell
end if
Re: Bind Transmission to Interface with Applescript
Hey,
I've been using this script for quite a while now. I migrated to MacOS Mavericks recently and now it does not work properly anymore. I suspect it is conntected to a different outpunt of the ifconfi -lu command. If conntecte to VPN it returns ‚lo0 en0 en1 bridge0 p2p0 tun0‘, if not only ‚lo0 en0 en1 bridge0 p2p0‘. I have to admit I have no idea what these OpenVPN returns mean, so … do I just have to change the wanted output in the script?
Thanks, I apprecciate any support.
I've been using this script for quite a while now. I migrated to MacOS Mavericks recently and now it does not work properly anymore. I suspect it is conntected to a different outpunt of the ifconfi -lu command. If conntecte to VPN it returns ‚lo0 en0 en1 bridge0 p2p0 tun0‘, if not only ‚lo0 en0 en1 bridge0 p2p0‘. I have to admit I have no idea what these OpenVPN returns mean, so … do I just have to change the wanted output in the script?
Thanks, I apprecciate any support.