Check and change VPN connection

Hi! I wonder if there’s a chance to support macOS's built-in VPN connections. It would be really great to use some If/then conditions like "is connected to a specific VPN" and the simple actions "connect to VPN"/"disconnect". I know there are command line workarounds, but these aren't very Keyboard Maestro like :wink:
Thanks for considering!

You can return values to a Variable and then use the variable for and IF/Then.

Use a shell script to check network interfaces:

scutil --nc list | grep -i "YourVPNName" | grep Connected

To connect or disconnect use you can also do this via shell script as you pointed out in Keyboard Maestro.

scutil --nc start "VPN_NAME"
scutil --nc stop "VPN_NAME"

Hopefully that points you in the right direction.

You also probably know this but you can use connections to specific networks within Keyboard Maestro.

https://wiki.keyboardmaestro.com/condition/Wireless_Network?s[]=network

Hi, thank you for taking the time and putting together this response. Unfortunately this won't connect to my company's VPN server because it uses a shared secret authentication.
As a workaround I ended up using the macOS Shortcuts app, which supports connecting to VPN servers without the command line "hack". Here's to hoping we'll get a more elegant KM solution in the future!

Thanks for posting your results and what you came up with.