I would like to save some mouse clicks and keystrokes by initiating VPN connection from command line. Is there tool for this in Mac OS X? Ideally, it should accept VPN connection name and password and start VPN connection.

Update: I'm talking about builtin VPN client for Cisco IPSec VPN.

  • 1
    There are numerous VPN protocols. Are we talking about the protocols supported by the built-in VPN implementation (PPTP, L2TP or Cisco)? Commented Aug 17, 2011 at 10:48
  • Yes, I'm talking about builtin VPN client in Mac, specifically "Cisco IPSec". Commented Aug 17, 2011 at 11:03

1 Answer 1


Your best bet seems to be AppleScript:

tell application "System Events"
   tell current location of network preferences
       set VPNservice to service "VPN (L2TP) 2" -- name of the VPN service
       if exists VPNservice then connect VPNservice
   end tell
end tell

(from http://macscripter.net/viewtopic.php?id=22992)

As for entering a username and password, I'm not sure how you could do that. Further scripting could get you the frontmost window and input the username and password, then submit the dialog, but as I don't have a Cisco VPN to test I couldn't tell you how to set that up.

If you have the actual Cisco VPN client installed (which afaik is not necessary), you could just use this command:

open /Applications/VPNClient.app --args -c -user <YourUsername> -pwd <YourPassword> <ProfileNameToConnect>
  • I don't have additional Cisco VPN client installed, I use builtin VPN in Mac. Thanks, I will try this. Commented Aug 17, 2011 at 18:28
  • I would recommend not putting the password on the command line. It can be read by other users.
    – bahamat
    Commented Aug 17, 2011 at 19:01
  • @bahamat, sure, but since I'm the only user on my computer, I don't care. Commented Aug 20, 2011 at 17:05
  • Exactly what I was looking for, BUT When I try this script I get "Syntax Error: End of line expected but found identifier" and it highlights the first occurrence of the word "location".
    – user14038
    Commented Nov 22, 2011 at 23:39
  • @bahamat if you only specify the -c option, then you get the GUI window prompt for the username and password (for the default profile).
    – haridsv
    Commented Dec 9, 2012 at 10:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .