Skip to content

Instantly share code, notes, and snippets.

@scoutman57
Forked from twksos/CiscoVPNConnection.scpt
Created May 18, 2016 14:25
Show Gist options
  • Save scoutman57/de8a1e646b01e2bf46a6de07cfcb225f to your computer and use it in GitHub Desktop.
Save scoutman57/de8a1e646b01e2bf46a6de07cfcb225f to your computer and use it in GitHub Desktop.
Cisco VPN connection auto connect AppleScript
-- Please set your vpn connection name and password here
set VPNName to "VPN name"
set VPNpassword to "VPN password"
tell application "System Events"
tell current location of network preferences
set VPNService to service VPNName
end tell
set isConnected to connected of current configuration of VPNService
if isConnected then
disconnect VPNService
else
connect VPNService
set startTime to current date
repeat until exists (static text 1 of window 1 of application process "UserNotificationCenter" whose name is "Enter your user authentication")
if (current date) - startTime is greater than 8 then
error "Could not connect, the connection dialog did not pop up"
exit repeat
end if
delay 0.2
end repeat
set theProcess to application process "UserNotificationCenter"
set theWindow to window 1 of theProcess
set theDescription to static text 2 of theWindow
if name of theDescription is "Enter your user authentication" then
set theControls to get entire contents of theWindow
set thePassword to text field 1 of theWindow whose description is "secure text field"
set value of thePassword to VPNpassword
set theOKButton to button 1 of theWindow whose title is "OK"
click theOKButton
repeat until exists (button 1 of window 1 of application process "UserNotificationCenter" whose title is "Disconnect")
if exists (button 1 of window 1 of application process "UserNotificationCenter" whose title is "Cancel") then
set theCancelButton to button 1 of theWindow whose title is "Cancel"
click theCancelButton
error "please check password in the script."
exit repeat
end if
delay 0.2
end repeat
set theOKButton to button 1 of theWindow whose title is "OK"
click theOKButton
end if
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment