Skip to content

Instantly share code, notes, and snippets.

@twksos
Last active July 31, 2023 20:50
Show Gist options
  • Save twksos/44b45abf5263635776ec to your computer and use it in GitHub Desktop.
Save twksos/44b45abf5263635776ec 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
@ferreirafabio
Copy link

best combine this with https://github.com/plyint/encpass.sh to not store unencrypted passwords in scripts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment