Skip to Main Content

Force Mac OS X to Automatically Reconnect to VPN


A VPN (Virtual Private Network) is a great way to browse the web securely, and OS X has a VPN option built right into it. The problem is that it doesn't always automatically connect when you boot up your computer, or after it disconnects for some reason. A simple Applescript over on Stack Exchange solves this problem.

To enable this function, open up Applescript (Applications > Utilities) and paste in this code (replace "VPN University" with the service name you use):

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 tellend idle

Then, save the script as an application with the "Stay Open" box checked. Now, when you're browsing with a VPN, say, at a coffee shop, or just at your own house, OS X will automatically reconnect if the connection drops for some reason. The Applescript should work in both Mountain Lion and Lion. Head over to StackExchange for the full step-by-step instructions.

Auto connect VPN upon login/boot | StackExchange via One Thing Well