I always connect to my VPN endpoint so that all my traffic leaves my devices over a secure tunnel. However, the biggest flaw with the inbuilt Apple VPN client is that it won’t auto reestablish the VPN session if it dies or you wake the laptop from sleep. The wifi at conferences is pretty flakey and I loose the connection regularly, as such when the connection is reestablished the VPN tunnel does not get reopened. This can lead to me sending data over the open air.
I decided to create a simple app using AppleScript and loosely based it on the code found here. I improved the code to make sure that there was network connectivity before attempting to start the VPN session.
The code is here should you wish to make it yourself:
tell application "System Events"
tell current location of network preferences
set myConnection to the service "home VPN"
if myConnection is not null then
set networkUp to true -- assume the best
do shell script "ping -c 1 -t 2 www.google.com"
on error -- network is down
set networkUp to false
if current configuration of myConnection is not connected and networkUp then
say "Reconnecting VPN"
What should be noted is that my VPN connection is called “home VPN” so you will need to change this yourself to match the name of your VPN connection name. To do this just open the script using AppleScript.
Here’s the app for your use https://www.phillips321.co.uk/downloads/AutoVPN.app.zip be sure to rename the VPN connection name in the script from “home VPN” to the name of your connection.