Skip to content

Instantly share code, notes, and snippets.

@hfeeki
Forked from rhybroy/pptp_autocon.applescript
Last active August 29, 2015 14:07
Show Gist options
  • Save hfeeki/c7260cd59b1d5f8d20e1 to your computer and use it in GitHub Desktop.
Save hfeeki/c7260cd59b1d5f8d20e1 to your computer and use it in GitHub Desktop.
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
#!/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