Autoconnect VPN OSX

From ivc wiki
Jump to navigationJump to search

To make OS X auto-connect and re-connect to a VPN, use this AppleScript to automate the process. When compiled as an application, it will stay in the background and watches whether the VPN connection is active or not - and connects when needed.

Paste the following into the AppleScript editor and change the "RPI VPN" with the name of your VPN configuration name in the Network system preferences.

on idle
	tell application "System Events"
		tell current location of network preferences
			set myConnection to the service "RPI VPN"
			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

Save and pick File format Application, put in /Applications and make it auto-start by adding it to the Login Items list in the Users and Groups system preferences.