In Mac OS X 10.11, Opening a VPN connection window with the command line gives me an error

后端 未结 5 669
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 12:32

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         


        
5条回答
  •  借酒劲吻你
    2021-02-04 13:09

    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.

提交回复
热议问题