Skip to content

Instantly share code, notes, and snippets.

@joaocarmo
Created September 14, 2020 12:44
Show Gist options
  • Save joaocarmo/b4be0b41aee4a9f15690f44f260abd48 to your computer and use it in GitHub Desktop.
Save joaocarmo/b4be0b41aee4a9f15690f44f260abd48 to your computer and use it in GitHub Desktop.
Automate the authentication of Cisco AnyConnect Secure Mobility Client in macOS
#!/usr/bin/osascript
--Variables
set vpnServer to "vpn.mydomain.com"
set vpnPassword to "myb64pwd"
set vpnAppBundleName to "Cisco AnyConnect Secure Mobility Client"
set vpnAppBundleId to "com.cisco.anyconnect.gui"
set keyCodeDelete to 51
set keyCodeReturn to 36
set tinyDelay to 1
set smallDelay to 3
--Decode base64 string
on base64decode(str)
return do shell script "base64 -D <<<" & quoted form of str
end base64decode
--Open the application
tell application vpnAppBundleName
activate
end tell
--Decode
set decodedPwd to base64decode(vpnPassword)
--Main tell block
tell application "System Events"
delay tinyDelay
tell process vpnAppBundleName
set frontmost to true
set visible to true
--Set the VPN server
keystroke "a" using command down
key code keyCodeDelete
keystroke vpnServer
key code keyCodeReturn
--Wait for the connection and authentication dialog
delay smallDelay
--Input authentication
keystroke decodedPwd
key code keyCodeReturn
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment