How to create a VPN shortcut in OS X
With the aid of a short Automator workflow, AppleScript can have you connected to your VPN with a single keystroke.
A virtual private network, or VPN, is a method of securely connecting to a network from a remote location, and is commonly used in work environments. While some institutions require the use of third-party VPN client software, others allow the use of Apple's built-in VPN clients.
In these cases, you can choose to enable the VPN menu in the OS X menu bar, and can then use it to quickly establish a VPN connection. However, if you are regularly connecting to your VPN, you may choose to also implement a hot-key shortcut to speed things up a bit more.
To do this, you will need to use Apple's Automator program to link a small AppleScript routine to a hot key, which can be done by following this procedure:
- Open the Automator utility and create a new "Service" workflow.
- Set the workflow to receive "no input" in "any application" in the top-most menus.
- Add the "Run AppleScript" action to the workflow, and replace its script contents with the following (adapted from MarkupBoy):
tell application "System Events"
tell current location of network preferences
set VPN to "SERVICE NAME"
set VPNactive to connected of current configuration of service VPN
if VPNactive then
disconnect service VPN
connect service VPN
Be sure to replace SERVICE NAME with the name of your VPN connection, which can be looked up in the Network system preferences (if the name is truncated, click the Advanced... button and view the full name at the top of the Advanced Settings panel).
- Save the workflow with a name like "Connect to VPN"
When this is finished, go to the Keyboard system preferences and select the Keyboard Shortcuts tab, where you can locate the "Connect to VPN" service in the Services section, and assign a custom keyboard shortcut to it. You should now be able to toggle your VPN connection on and off from within any application by using this shortcut.