Created
April 25, 2017 14:02
-
-
Save patricksimpson/a5fc6dafe292a310808525b95324978a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
keychainItem=vpn # this name has to match "Account" for the entry you make in keychain | |
VPNName="" # match the name of the VPN service to run | |
function isnt_connected () { | |
scutil --nc status "$VPNName" | sed -n 1p | grep -qv Connected | |
} | |
get_pw () { | |
security 2>&1 >/dev/null find-generic-password -ga $keychainItem \ | |
|ruby -e 'print $1 if STDIN.gets =~ /^password: "(.*)"$/' | |
} | |
echo "fetching VPN credentials from keychain account \"$keychainItem\"" | |
echo "Using VPN service: $VPNName" | |
if isnt_connected $VPNName; then | |
echo "connecting to VPN" | |
scutil --nc start "$VPNName" | |
sleep 2.7 | |
osascript -e "tell application \"System Events\" to keystroke \"$(get_pw)\"" | |
osascript -e "tell application \"System Events\" to keystroke return" | |
sleep 2 | |
else | |
echo "Already Connected to VPN..." | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment