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.

link|improve this question

74% accept rate
feedback

2 Answers

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.

link|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
feedback
up vote 1 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."

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.