This script will be usefull if you want to enable VPN automatically on coming to work and to disable it on escaping from work using great Control Plane app.
It is assumed that you use Tunnelblick to manage VPN connections.
To connect to VPN:
set q to "<your_connection_name>"
tell application "Tunnelblick"
set configs to get name of configurations
if q is in configs then
set s to get state of first configuration where name = q
if s is equal to "CONNECTED" then
else
activate
if connect q then
else
display notification "Could not connect to: " & q
end if
end if
else
display notification "There is no VPN named: " & q
end if
end tell
To disconnect from VPN:
set q to "<your_connection_name>"
tell application "Tunnelblick"
set configs to get name of configurations
if q is in configs then
set s to get state of first configuration where name = q
if s is equal to "CONNECTED" then
if disconnect q then
else
display notification "Could not disconnect from: " & q
end if
end if
else
display notification "There is no VPN named: " & q
end if
end tell