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.

Automator VPN connection workflow
This workflow will connect a VPN service called 'MyVPN (PPTP)' when run (click for larger view). Screenshot by Topher Kessler/CNET

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:

  1. Open the Automator utility and create a new "Service" workflow.
  2. Set the workflow to receive "no input" in "any application" in the top-most menus.
  3. 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
              else
                   connect service VPN
              end if
         end tell
    end tell

    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).

  4. 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.



Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.

About the author

    Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.

     

    Join the discussion

    Conversation powered by Livefyre

    Don't Miss
    Hot Products
    Trending on CNET

    HOT ON CNET

    Get ready for iOS 8

    Here's what you need to know before downloading iOS 8 on your iPhone or iPad.