Last Updated: September 30, 2017
· ernestom

Automatically connect to a VPN on startup in OSX

  • Create a file called connectvpn.applescript using AppleScript Editor with the following:

tell application "System Events"
    tell current location of network preferences
        set VPNService to service "MYVPNNAME"
        if exists VPNService then
            connect VPNService
        end if
    end tell
end tell

Substitute "MYVPNNAME" with the name of your VPN service as it is shown in the settings app.
Save as application.
Add the saved .app to the boot items in the startup items in the users and group panel in the settings app. Don't forget to check the hide checkbox.
Say Thanks

3 Responses
Add your response


Works well. To save as application, you need the "Export" menu option

over 1 year ago ·

Drawback is if the Applescript is unable to connect as the VPN service is down or your internet connection is not ready yet. The alternative is to use an App which will also help you to keep the connection up and reconnect in case the VPN service drops the connection. A nice and new VPN auto reconnect app is "VPN Monitor" in the app store, it reconnects instantly the moment a VPN connection drops, is able to reconnect to a different VPN service if the preferred service is down, connects at start-up, keeps track of your downtime and uses a minimum of system resources to run in the background as a statusbar application. VPN Monitor

over 1 year ago ·

That won't work with IKEv2 VPNs. Here's how you can do that using a different AppleScript

2 months ago ·
Filed Under