Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using my school's VPN service to surf on netflix. I have to connect to the VPN most of the time. My school uses Cisco AnyConnect Secure Mobility Client. I have to enter password and accept a banner every time I connect. Is there a way to automate this connection on OS X?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

If you are using OS X to control your connection: enter image description here

The reason this comes up is because the Cisco box you are connecting to is forcing interaction. It's actually a setting on the Cisco VPN aggregator that enforces security. Apple doesn't provide circumvention for (Apple Script/Automator) this as part of the agreement Cisco made with Apple (according to both Cisco and Apple). I've investigated this before and this was the answer I was given by both sides.

The same is true with the Cisco OS X VPN client.

share|improve this answer

Yes, you can automate this using AppleScript.

Here's a script I use:

-- 1. Place in ~/Library/Scripts and enable the Applescript menu via the Applescript Editor
--    (Or export to .app to run from spotlight.)
-- 2. Substitute "vpn.example.com", "username" and "redacted" 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


-- AnyConnect now refered to as targetApp
set targetApp to "Cisco AnyConnect Secure Mobility Client"


-- 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"
        repeat until (window 1 of process targetApp exists)
            delay 1
        end repeat
        tell process targetApp
            keystroke ("vpn.example.com" as string)
            keystroke return
        end tell
        repeat until (window 2 of process targetApp exists)
            delay 1
        end repeat
        tell process targetApp
            keystroke (tab) using {shift down}
            keystroke ("username" as string)
            keystroke tab
            keystroke ("redacted" as string)
            keystroke return
        end tell
        delay 1
        tell process targetApp
            keystroke return
        end tell

    end tell
end if

This is a script I found and tweaked; I'm not sure who the original author is as there are several version floating around. I got it from https://gist.github.com/twksos/44b45abf5263635776ec

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.