Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@dniemeyer

This comment has been minimized.

Copy link

dniemeyer commented Jan 6, 2015

Hello Kevin... how do I input the SecurID's PIN so it can generate the Passcode correctly?

@benjamindsnow

This comment has been minimized.

Copy link

benjamindsnow commented Feb 11, 2015

Thanks for this. Here's an improvement:

repeat until (window "Cisco AnyConnect - Banner" of process "Cisco AnyConnect Secure Mobility Client" exists)
    delay 1
end repeat
click button "Accept" of window "Cisco AnyConnect - Banner" of application process "Cisco AnyConnect Secure Mobility Client"
@yohayg

This comment has been minimized.

Copy link

yohayg commented Dec 18, 2016

Thanks. It helped a lot.
I have added the following code to support cases where the client is running by default in the menu bar:
tell application "System Events" to tell process "Cisco AnyConnect Secure Mobility Client"
tell menu bar item 1 of menu bar 2
click
click menu item "Show AnyConnect Window" of menu 1
end tell
end tell

@degreecy

This comment has been minimized.

Copy link

degreecy commented Dec 8, 2017

Any ideas how to adapt for MobilePass ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.