There is no way to save a password when logging into a Cisco IPSec VPN on a Macintosh operating system (macOS).
The best solution for me is writing an AppleScript in Automator, or running it from the command line, to automate the login process.
AppleScript in Automator
-
Open Apple’s Automator,
-
Choose
New Document
-
Select
Service
The service created hasreceives selected
text
by default. It means you need to select text or having focus in a text editor to enable the service.
-
Try to search for action
Run AppleScript
. Then, drag the action into the right-hand-side.
-
Paste below code into the editor,
on run {input, parameters}
set vpn_name to "'your VPN name'"
set user_name to "your username"
set passwd to "your password"
tell application "System Events"
set rc to do shell script "scutil --nc status " & vpn_name
if rc starts with "Disconnected" then
do shell script "scutil --nc start " & vpn_name & " --user " & user_name
delay 3
keystroke passwd
keystroke return
end if
end tell
return input
end run
- Update
vpn_name
,username
andpasswd
in the script.
You can refer to the screenshot below for the vpn_name
, which is VPN (Cisco IPSec)
. The script uses scutil --nc status
to check the VPN connection status, and scutil --nc start
to initiate the VPN connection. Typically, the VPN login dialog appears within 3 seconds. If your laptop is slow, please update the value in delay 3
. To automate the process, try running the script using the play button and observe how it works.
-
Save the script with a name such as
VPN Login
.
In theSystem Preferences -> Keyboard -> Shortcuts
, you can find the automation script. Assign a shortcut key. By default, the script is assigned to the Text service during its creation. To use the keyboard shortcut, you will need to select some text or have focus in a text editor enabled.
-
Try selecting text from a text editor, such as Atom. With the proper shortcut key set up, you should be able to automate the VPN login. This script should work with Sierra or earlier versions of macOS, although I haven’t tested it on older systems myself. Please let me know if you have any results using this method on older macOS platforms
AppleScript from command line
-
Open Apple’s Script Editor,
-
Choose
New Document
-
Paste below code into the editor. Please refers to AppleScript in Automator
set vpn_name to "'your VPN name'"
set user_name to "your username"
set passwd to "your password"
tell application "System Events"
set rc to do shell script "scutil --nc status " & vpn_name
if rc starts with "Disconnected" then
do shell script "scutil --nc start " & vpn_name & " --user " & user_name
delay 3
keystroke passwd
keystroke return
end if
end tell
- Save the script. You can run the script with
osascript [programfile]
from Terminal.
Have fun!