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
The Problem: The issue was I got this error.
Can’t get «class svce» "MY VPN" of «class locc» of «class netp» of application "System Events".
System Events got an error: Can’t get service "My VPN" of current location of network preferences. (-1728)
The Reason: I am using IKEv2 services. It seems the Apple Script (which I found all over the internet) fails to work with this. You can find details in the link below.
The solution: Timac wrote a script to solve this problem. I simply downloaded the precompiled app here. https://blog.timac.org/2018/0719-vpnstatus/
If you are interested in the source code that makes it work, you can find it on GitHub here: https://github.com/Timac/VPNStatus
You can also dig deeper into the problem if you are that sort of person on that link. It gives details.
If you are simply looking for a solution to Auto Connect your VPN, the VPNstatus app worked for me.