Last Updated: February 25, 2016
·
1.709K
· athal7

Forget the mouse when connecting to VPN

So here's the scene: you've just completed that awesome new feature and you can't wait to get it out into the wild. You go to push to source control, but wait, you're not connected to the VPN. So what do you do?

Option 1: Use the mouse to click that little icon in the OSX menu bar.

Heck no, you're a software engineer, you don't need a mouse!

Option 2: Type vpn in your shell prompt!

But how do I do that?

Step 1:
save this applescript (with the vpn name) somewhere useful, maybe your user directory:

tell application "System Events"
  tell current location of network preferences
    set VPNservice to service "NAME_OF_VPN"
    if exists VPNservice then connect VPNservice
  end tell
end tell

Step 2:
alias vpn to execute that applescript

alias vpn='osascript ~/openvpn.applescript'

And you're done! Now just type vpn in your shell prompt and you'll be able to type in your vpn password without having to use the mouse!

courtesy of https://github.com/webandy

2 Responses
Add your response

Hey Andrew, thanks for the tip. A few things I needed to do to make this work on my computer:

alias vpn='osascript ~/openvpn.applescript'
that line was missing the ending '

To be able to copy and paste the alias call above, needed to make sure the file I created in my user directory was named "openvpn.applescript".

Finally, the name "MyVPN" needed to be adjusted to "VPN (Cisco IPSec)". I found this name by opening "System Preferences", going to "Network", and then scrolling down to find what my VPN configuration was named.

over 1 year ago ·

@hunterae thanks so much for the notes. updating to add the ending quote. i should have been more clear that the name "MyVPN" had to match the name of the vpn, I'll update that too

over 1 year ago ·