MacOS – Getting VPN to auto-reconnect on connection drop

macosvpn

I use the built-in VPN on Mac OS X 10.7.3. It's IPSec, FWIW. From time to time, it disconnects (probably an issue with my corporate server). Is there a way to get it to automatically reconnect? Sometimes I don't notice for a while, which is kinda annoying.

Best Answer

You could use the following AppleScript, save it as an application and set it to be a agent (no dock icon).

This script will setup a VPN connection when there is none. Therefore, it should also reconnect shortly after your connection drops. You can change the interval to check your VPN connection, it's 120 seconds in the script.

on idle
    tell application "System Events"
        tell current location of network preferences
            set myConnection to the service "VPN University"
            if myConnection is not null then
                if current configuration of myConnection is not connected then
                    connect myConnection
                end if
            end if
        end tell
        return 120
    end tell
end idle

I've explained how to set this up in this answer.