Can a Keyboard Shortcut be Set to Connect to VPN?

Solution 1:

You could create an AppleScript which would run a shell script to racoonctl - the specific commands will depend upon your VPN connection. Then use Script Utility to enable the global Script Menu, then add a new keyboard shortcut in System Preferences > Keyboard > Keyboard Shortcuts, and assign it to the script (or use a launcher utility such as Quicksilver).

Solution 2:

  1. 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.
  2. Add the "Run AppleScript" action to the workflow, and replace its script contents with the following:

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

  3. Save the workflow with a name like "Connect to VPN"

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

I personally assign `Control + Option + Command + V' to toggle my VPN.

From cnet.