Skip to content

Instantly share code, notes, and snippets.

@eapostol
Forked from kevinberny/AnyConnect_SecurID
Created April 24, 2018 14:29
Show Gist options
  • Save eapostol/b20f55957781c11caaff3dc771716cc6 to your computer and use it in GitHub Desktop.
Save eapostol/b20f55957781c11caaff3dc771716cc6 to your computer and use it in GitHub Desktop.
Mac OS X AppleScript to automate RSA SecurID pin & Cisco AnyConnect client connection. Leverages keychain. Cobbled together from several other previous postings
set the clipboard to ""
set appname to "SecurID"
set thePin to RsaTokenPin()
activate application appname
do shell script "networksetup -setairportpower en0 on"
tell application appname
activate
tell application "System Events"
keystroke thePin -- type the pin number
key code 36 -- return key
delay 0.75 -- wait for token appear
key code 48 -- press tab
key code 49 -- space (to hit the copy button)
end tell
end tell
delay 0.5 -- wait
quit application appname
on RsaTokenPin()
return (do shell script "security -q find-generic-password -gl rsatoken 2>&1 | egrep '^password' | awk -F\\\" '{print $2}'")
end RsaTokenPin
tell application "Cisco AnyConnect Secure Mobility Client"
activate
end tell
repeat until application "Cisco AnyConnect Secure Mobility Client" is running
delay 1
end repeat
tell application "System Events"
repeat until (window 1 of process "Cisco AnyConnect Secure Mobility Client" exists)
delay 1
end repeat
click button "Connect" of window 1 of application process "Cisco AnyConnect Secure Mobility Client"
repeat until (window 2 of process "Cisco AnyConnect Secure Mobility Client" exists)
delay 1
end repeat
tell process "Cisco AnyConnect Secure Mobility Client"
keystroke "v" using {command down}
delay 1
keystroke return
-- click button "OK"
end tell
(* repeat until (window 1 of process "Cisco AnyConnect Secure Mobility Client" exists)
delay 1
end repeat
click button "Accept" of window 1 of application process "Cisco AnyConnect Secure Mobility Client"
*)
delay 8
keystroke return
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment