Advertisement
Guest User

Untitled

a guest
May 26th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. -- 1. Place in ~/Library/Scripts and enable the Applescript menu via the Applescript Editor
  2. -- (Or export to .app to run from spotlight.)
  3. -- 2. Substitute "vpn.example.com" and "redacted" for your VPN server and password
  4. -- 3. Open Security & Privacy System Preferences, go to Privacy, Accessibility
  5. -- 4. Enable Applescript Editor and System UI Server (or for this .app if so exported)
  6. -- 5. Trigger script from the menu (or run from spotlight)
  7. -- 6. Enjoy being connected
  8. -- 7. Run script again to close connection
  9.  
  10.  
  11. -- AnyConnect now refered to as targetApp
  12. set targetApp to "Cisco AnyConnect Secure Mobility Client"
  13.  
  14.  
  15. -- Determine if AnyConnect is currently running
  16. tell application "System Events"
  17. set processExists to exists process targetApp
  18. end tell
  19.  
  20.  
  21. -- Close connection if running; else start connection and fill in password
  22. if processExists is true then
  23. tell application targetApp
  24. quit
  25. end tell
  26. else
  27. tell application targetApp
  28. activate
  29. end tell
  30.  
  31. tell application "System Events"
  32. -- Wait for first window to open. Do nothing.
  33. repeat until (window 1 of process targetApp exists)
  34. delay 1
  35. end repeat
  36.  
  37. -- Wait for second window to open. Enter password.
  38. repeat until (window 2 of process targetApp exists)
  39. delay 2
  40. end repeat
  41. tell process targetApp
  42. keystroke ("redacted" as string)
  43. keystroke return
  44. end tell
  45.  
  46. end tell
  47. end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement