Auto-login for Cisco Anyconnect on Mac
1 Introduction
This blog post explains how to write an AppleScript to automate the log-in procedure for Cisco Anyconnect on a Mac. The post provides a two-step guide on:
- How to write the AppleScript to automate the procedure?
- How to make the script an actionable program and access it easily like an app?
1.1 Why is it needed?
Here is an example of why this is useful:
If you want to submit jobs from home to the high-performance computer at school, you need to log in to the school VPN through Cisco Anyconnect every time. Sometimes, you need to log in every day.
Usually, connecting to the school VPN address requires a few steps:
- Open Anyconnect.
- Press
Connect
to your VPN address. - In the pop-up window, type your
Username
andPassword
. - Press
Log in
. - Wait a while, a push will appear on your phone, confirm it. Then connection completed.
Since Cisco Anyconnect doesn't remember your ID, password, or your computer every time, you need to repeat steps 1-5 every time. To save time (as an extreme lazy person), steps 2-4 can be completely automated, although step 5 is still necessary.

2 Apple Script for Automation
Open Script Editor
- path: /System/Applications/Utilities/Script Editor.app
Click
New Document
to create a new scriptAdd the script code (or download the script file here)
- Find the following part and change to your
Username
andPassword
1
2
3tell application "System Events" to keystroke "Username"
tell application "System Events" to keystroke tab
tell application "System Events" to keystroke "Password"
- Find the following part and change to your
Run it by clicking ▶️ to test if it works in your computer
2.1 Apple Script Codes
This code has been modified using the scripts from sgsvnk/cisco-vpn-auto-login.
The initial if
loop is designed to launch Cisco
AnyConnect on your Mac.
1 | if application "Cisco AnyConnect Secure Mobility Client" is running then |
Here are the modifications I made: 1. Added a time delay after connecting to the VPN address because I noticed that it takes a while for the login window to appear. 2. Added steps to automatically type in your username and password and then press enter.
3 Turn this script to an application
Here is a apple support page about Save a script as an app in Script Editor on Mac
Export this script
Choose File Format as
Application
and give a name to this applicationNow you can find it in your application and call it out easily
4 Reference
https://support.apple.com/guide/script-editor/save-a-script-as-an-app-scpedt1072/mac