Applescript to Automatically Connect VPN
Recently got a MacBook and when I'm at home I use it to connect to my university's VPN connection. This works well except for the fact that it disconnects every time my laptop sleeps or locks so I wrote this applescript:
on idle
tell application "System Events"
tell current location of network preferences
set myConnection to the service "VPN University"
if myConnection is not null then
if current configuration of myConnection is not connected then
connect myConnection
end if
end if
end tell
return 120
end tell
end idle
I also edited the info.plist so that the application was completely hidden at all times. This works well whilst I have the ethernet cable attached and want to be on the VPN, but as soon as I move away from my desk I want to be on the wifi and the continuous 'failed to join VPN' error messages are quite annoying.
I was wondering if there was an applescript workaround that would somehow test whether I have the ethernet cable attached? I realise I may be asking a bit much.
Thanks.
MacBook Pro with Retina display, OS X Mavericks (10.9.4)