Skip to content

Instantly share code, notes, and snippets.

@Bowbaq
Last active August 29, 2015 14:16
Show Gist options
  • Save Bowbaq/f72c69418c9a42b26ea8 to your computer and use it in GitHub Desktop.
Save Bowbaq/f72c69418c9a42b26ea8 to your computer and use it in GitHub Desktop.
Auto reconnect VPN
-- Instructions to compile the app
-- http://apple.stackexchange.com/questions/32392/how-to-auto-connect-to-vpn-upon-login-boot/32395#32395
on idle
-- set the name of the VPN
set vpn to "<name of the vpn>"
-- set the password
set passwd to "<your password>"
tell application "System Events"
tell current location of network preferences
-- set the name of the VPN service from your Network Settings
set VPNService to the service vpn
if VPNService is not null then
if current configuration of VPNService is not connected then
connect VPNService
-- wait 1.5 seconds before typing in the password
delay 1.5
tell application id "com.apple.systemevents"
-- type in the password
repeat with c in (characters in passwd)
keystroke c
-- delay (random from 0.1 to 0.5)
end repeat
-- finish with Enter
keystroke return
-- wait 1.5 seconds for connection
delay 1.5
if current configuration of VPNService is connected then
-- get rid of confirmation dialog
keystroke return
else
key code 53
end if
end tell
end if
else
log vpn & " does not exist"
end if
end tell
end tell
-- call this every minute
return 60
end idle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment