Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
1  
There are numerous VPN protocols. Are we talking about the protocols supported by the built-in VPN implementation (PPTP, L2TP or Cisco)? –  Sören Kuklau Aug 17 '11 at 10:48
    
Yes, I'm talking about builtin VPN client in Mac, specifically "Cisco IPSec". –  Peter Štibraný Aug 17 '11 at 11:03

1 Answer 1

up vote 9 down vote accepted

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>
share|improve this answer
    
I don't have additional Cisco VPN client installed, I use builtin VPN in Mac. Thanks, I will try this. –  Peter Štibraný Aug 17 '11 at 18:28
    
I would recommend not putting the password on the command line. It can be read by other users. –  bahamat Aug 17 '11 at 19:01
    
@bahamat, sure, but since I'm the only user on my computer, I don't care. –  Peter Štibraný Aug 20 '11 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 Nov 22 '11 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 Dec 9 '12 at 10:07

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.