On Mac OS X <= 10.10, I could run the following command to open a VPN connection window:
function go-vpn {
/usr/bin/env osascript <<-EOF
tell applicatio
Further to Oliver's answer, in macOS 10.12.6, the output of scutil --nc status
has changed so that the match 'Connected' also matches for 'ConnectedCount'. Not sure in which version of macOS this changed.
I've made a slight change to the test to just look at the first line of output, which is really what needs to be checked.
VPN="YOUR_VPN_NAME"
IS_CONNECTED=$(test -z `scutil --nc status "$VPN" | head -n 1 | grep Connected` && echo 0 || echo 1);
if [ $IS_CONNECTED = 1 ]; then
scutil --nc stop "$VPN"
else
scutil --nc start "$VPN"
fi
This works for me on macOs 10.12.6. Hope it helps others.