Last active
April 5, 2017 12:17
-
-
Save rhybroy/5889540 to your computer and use it in GitHub Desktop.
auto connect/disconnect pptp-vpn from the command line for mac
This file contains hidden or 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
set msg to "" | |
tell application "System Events" | |
tell current location of network preferences | |
set VPNservice to service "VPN (PPTP)" | |
if exists VPNservice then | |
set isConnected to connected of current configuration of VPNservice | |
if isConnected then | |
disconnect VPNservice | |
set msg to "Disconnected" | |
else | |
connect VPNservice | |
set isConnectedCheck to false | |
#also can try wait util success: repeat until isConnectedCheck | |
#now wait in 20s | |
set x to 0 | |
repeat 10 times | |
set x to (x + 1) | |
set isConnectedCheck to connected of current configuration of VPNservice | |
if isConnectedCheck then | |
set msg to "Connected success in " & (x * 2) & "s " | |
exit repeat | |
else | |
delay 2 | |
end if | |
end repeat | |
if not isConnectedCheck then | |
set msg to "Connect fail in 20s" | |
end if | |
end if | |
end if | |
end tell | |
end tell | |
return text 1 thru -2 of msg |
This file contains hidden or 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
#!/bin/sh - | |
osascript $YOURPATH/pptp_autocon.applescript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useage:
modify the $YOURPATH in vpn where is the pptp_autocon.scpt you put
then put vpn shell script in $PATH
chmod +x ~/bin/vpn
Done