I added VPN connectivity to my network and I wanted to make sure the connection to the remote VPN was always running. One way to do this is to use AppleScript to check the connection status. The problem I had was that the AppleScripts that I found no longer worked with MacOS Sierra.
After some digging, I got it to work. Here’s my script:
set myVPN to "VPN (dallas)" -- set name of VPN connection
set isConnected to do shell script "scutil --nc show \"" & myVPN & "\" | grep -c Connected"
set isConnected to "0"
if isConnected = "0" then
do shell script "scutil --nc start \"" & myVPN & "\""
return 15 -- how often to check, seconds
Change the variable
myVPN to the name of your network connection. Here mine is
Also modify the
return value if you want the time between checks to be longer or shorter. Here I’ve set mine to 15 seconds.
These are the some of the pages that I started with. The instructions for script generation and auto-boot still apply. So you can still reference them for those other tasks:
Some other tech references which helped:
* “on idle” reference