Skip to content

Instantly share code, notes, and snippets.

@xVir
Created August 29, 2016 07:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xVir/da04911c67f9af430c5a78c887ec1eed to your computer and use it in GitHub Desktop.
Save xVir/da04911c67f9af430c5a78c887ec1eed to your computer and use it in GitHub Desktop.
Scripts for enabling and disabling VPN in Control Plane

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment