oy4vkg
Last Updated: September 30, 2017
·
11.16K
· ernestom
E8f4b515608fa13511cf7d27690484c2

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
</code></pre>


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
Respond

3 Responses
Add your response

15231
90fcebb2d0daef1dddcfef08a012330d

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

over 1 year ago ·
15954
21f8d3ef24351220cb0b935d5e155ea0

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 ·
29332

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

2 months ago ·
Filed Under