Skip to content

Instantly share code, notes, and snippets.

@prasanthj
Created July 18, 2016 08:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prasanthj/6749954dcfbab838242a0c36341d81d1 to your computer and use it in GitHub Desktop.
Save prasanthj/6749954dcfbab838242a0c36341d81d1 to your computer and use it in GitHub Desktop.
VPN auto-connect OS X El Capitan (Run this from Script Editor)
set vpn_name to "'VPN_NAME'"
tell application "System Events"
set rc to do shell script "scutil --nc status " & vpn_name
if rc starts with "Connected" then
do shell script "scutil --nc stop " & vpn_name
else
-- get current clipboard contents as a string
set CurrentClipboard to the clipboard as string
-- set the clipboad to your password
set the clipboard to "VPN_PASSWORD"
do shell script "scutil --nc start " & vpn_name
delay 2
-- paste clipboard contents into password box
keystroke "v" using {command down}
-- press "Enter"
keystroke return
-- wait 2 seconds to connect
delay 2
-- now reset the clipboard to what it was before we started
set the clipboard to CurrentClipboard
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment