Skip to content

Instantly share code, notes, and snippets.

@philz
Forked from andrewh/anyconnect.scpt
Last active July 4, 2017 14:06
Show Gist options
  • Save philz/ad57552ca839efa3a2dd to your computer and use it in GitHub Desktop.
Save philz/ad57552ca839efa3a2dd to your computer and use it in GitHub Desktop.
-- AppleScript to log into Cisco AnyConnect VPN
--
-- Based on https://gist.github.com/andrewh/7135352
--
-- 1. Edit the "vpn" variable below.
-- 2. Add your VPN password into your keychain. Use
-- "security add-generic-password -a VPN_HOST -s VPN_HOST
-- from the command line, and then edit the password using
-- the Keychain Access application.
-- 3. From AppleScript Editor, use File...Export to export
-- as an application; I anmed mine "Login to VPN"
-- 4. You'll need to grant permissions for "Login to VPN"
-- to access Privacy, Accessibility in Security & Privacy System Preferences
-- 5. Enjoy
set vpn to "VPN_HOST"
on getPW(keychainItemName)
do shell script "security 2>&1 >/dev/null find-generic-password -gl " & quoted form of keychainItemName & " | awk '{print $2}'"
return (text 2 thru -2 of result)
end getPW
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
tell process "Cisco AnyConnect Secure Mobility Client"
keystroke (vpn as string)
keystroke return
end tell
repeat until (window 2 of process "Cisco AnyConnect Secure Mobility Client" exists)
delay 1
end repeat
set pw to my getPW(vpn)
tell process "Cisco AnyConnect Secure Mobility Client"
keystroke (pw as string)
keystroke return
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment