TechNeate.com iPhoneate.com QueComico.com MiamiGlobalRadio.com

How to automatically connect to a VPN at startup or login on Mac OS X

by menorah / August 11, 2016 7:00 PM EDT

If you use a VPN on your Mac for work or personal reasons, you can have the Mac Automatically connect to the VPN service when your system starts or you log in. Or perhaps you simply want the VPN to automatically reconnect if the connection drops. This is easily achieved with a simple AppleScript, which we'll show you in the following tutorial.

Obviously you'll need a working VPN service on Mac OS for the script to work; otherwise, the script won't have anything to connect to during system startup and login.

How to automatically connect to a VPN at startup or login on Mac OS X

This automatic VPN connection script should work on any version of macOS or Mac OS X.

  • Open the "Script Editor" on your Mac; it's located inside the folder /Applications/Utilities /
  • Go to the File menu and choose "New"
  • Copy and paste the following AppleScript syntax into the new blank script editor:
 on idle tell application "System Events" tell current location of network preferences set myVPN to the service "VPN NAME" if myVPN is not null then if current configuration of myVPN is not connected then connect myVPN end if end if end tell return 60 end tell end idle
  • Replace "VPN NAME" with the name of the accompanying VPN network location found in the System Preferences Network Control Panel.

connect-vpn-applescript-mac

  • Go back to the "File" menu and select "Save"
  • In the 'Format' drop-down menu, choose "Applications"
  • Check the box next to "Stay open"

save-vpn-script-as-application-mac

  • Now choose "Save" and name the VPN script "scriptvpn" and place it somewhere easy to find.
  • Next, go to the main menu bar and select "System Preferences" and then go to the "Users & Groups" control panel.
  • Choose the active user's name and then select "Login Items" (startup). This depends on the system language settings.
  • Drag and drop the "scriptvpn" application you created so that it loads automatically at system startup and login.

auto-connect-vpn-on-boot-login-mac

And voila, that's it.