Skip to content

Instantly share code, notes, and snippets.

@epicserve
Created November 21, 2014 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epicserve/aa35f08f6bf78bc57067 to your computer and use it in GitHub Desktop.
Save epicserve/aa35f08f6bf78bc57067 to your computer and use it in GitHub Desktop.
-- 1. Place in ~/Library/Scripts and enable the Applescript menu via the Applescript Editor
-- (Or export to .app to run from spotlight.)
-- 2. Set domainName, vpnGroup and securePassword to their correct values for your VPN server and password
-- 3. Open Security & Privacy System Preferences, go to Privacy, Accessibility
-- 4. Enable Applescript Editor and System UI Server (or for this .app if so exported)
-- 5. Trigger script from the menu (or run from spotlight)
-- 6. Enjoy being connected
-- 7. Run script again to close connection
-- Settings
set targetApp to "Cisco AnyConnect Secure Mobility Client"
set domainName to "vpn.net.k-state.edu"
set securePassword to "redacted"
set vpnGroup to ".KStateVPNFull_Tunnel"
-- Determine if AnyConnect is currently running
tell application "System Events"
set processExists to exists process targetApp
end tell
-- Close connection if running; else start connection and fill in password
if processExists is true then
tell application targetApp
quit
end tell
else
tell application targetApp
activate
end tell
tell application "System Events"
-- Wait for first window to open. Do nothing.
repeat until (window 1 of process targetApp exists)
delay 1
end repeat
tell process targetApp
keystroke (domainName)
keystroke return
end tell
-- Wait for second window to open. Enter password.
repeat until (window 2 of process targetApp exists)
delay 2
end repeat
tell process targetApp
tell pop up button 1 of window 1
click
tell menu 1
click menu item vpnGroup
end tell
end tell
delay 1
tell text field 2 of window 2
keystroke (securePassword)
keystroke return
end tell
end tell
end tell
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment