The Need for Automatic VPN Connections
If you use a Virtual Private Network (VPN) for security or corporate compliance, you likely want it to connect the moment you log into your Mac. While some third-party VPN clients (like NordVPN or ExpressVPN) have “Launch on Startup” toggles built directly into their apps, the native macOS VPN configurations (configured in System Settings) do not offer a simple toggle to auto-connect on boot.
Instead of manually clicking the VPN icon in your menu bar every single morning, you can use Apple’s built-in Automator application to create a tiny script that seamlessly triggers the connection the moment you reach your desktop.
Step 1: Create an Automator Application
Automator is a powerful, built-in macOS utility designed to automate repetitive tasks.
- Open Finder, navigate to the Applications folder, and launch Automator.
- When prompted to choose a type for your document, select Application and click Choose.
Step 2: Add the AppleScript Action
We are going to use a simple AppleScript to tell macOS to connect to your specific VPN profile.
- In the left-hand column (under the “Library” pane), click on Utilities.
- In the second column, locate the action named Run AppleScript.
- Drag and drop the Run AppleScript action into the large empty workspace on the right.
Step 3: Write the Connection Script
Delete all the default placeholder text inside the AppleScript box, and replace it with the following code. Make sure you replace "Your VPN Name" with the exact, case-sensitive name of your VPN connection as it appears in System Settings.
on run {input, parameters}
tell application "System Events"
tell current location of network preferences
connect service "Your VPN Name"
end tell
end tell
return input
end run
Click the Play button (the triangle icon) in the top right corner of the Automator window to test the script. If it is successful, your VPN will connect immediately.
Now, save the application. Go to File > Save, name it something like AutoConnectVPN, and save it in your Applications folder.
Step 4: Add the Script to Login Items
Finally, we need to tell macOS to run this new application every time you log in.
- Open System Settings (or System Preferences on older Macs).
- Navigate to General > Login Items (or Users & Groups > Login Items).
- Click the + (plus) button under the “Open at Login” list.
- Browse to your Applications folder, select the
AutoConnectVPNapp you just created, and click Open.
That’s it! The next time you restart your Mac and log in, Automator will silently run the script in the background and establish your secure VPN connection without any manual intervention.