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.

How can I start a VPN connection (it's already all configured) from a shell on OSX? I have looked through the man entry on net but I don't think that's it. launchctl might be more promising...

Edit: I've made the title more general because I think the question would apply to any kind of network connection.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

See this thread. Basically you can Applescript it. Here's a full example:

#!/bin/sh 
osascript <<END 
tell application "System Events"
   tell current location of network preferences
       set VPNservice to service "Your VPN Name"
       if exists VPNservice then connect VPNservice
   end tell
end tell
END

You can even make another script replacing the word "connect" for "disconnect."

share|improve this answer

You can toggle network connections' state by using networksetup -setnetworkserviceenabled NameOfService on/off, e.g.

networksetup -setnetworkserviceenabled "AirPort" off

to disable the AirPort connection.


Enabling VPN connections this way doesn't connect them (AFAICT) though.

share|improve this answer
    
Yes, -setairportpower is more specific to AirPort, but it's just an example. -setnetworkserviceenabled is more general. Also, they perform different actions: A disabled AirPort network connection cannot be powered on. –  Daniel Beck Apr 2 '11 at 23:35
    
Thanks @Daniel Beck, I put in an answer myself, after a bit of thinking horizontally about it ;) –  Yar Apr 3 '11 at 6:41

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.