Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
on idle
# Change these to your VPN's IP Address, and the VPN's name in your Mac's Network System Prefernces panel.
set vpnIPAddress to "111.222.333.444"
set vpnServiceName to "AlgoVPN"
set myIP to ""
set shellScriptCommands to
"dig +short", ¬
"dig TXT +short | awk -F'\"' '{ print $2}'", ¬
"curl", ¬
"curl -s | grep -o \"[[:digit:].]\\+\"", ¬
repeat with shellScriptCommand in shellScriptCommands
set myIP to do shell script shellScriptCommand
exit repeat # if successful
on error errorMessage number errorNumber
end try
end repeat
if myIP is not equal to vpnIPAddress then
tell application "System Events"
tell process "SystemUIServer"
set vpnMenu to (menu bar item 1 of menu bar 1 where description is "VPN")
tell vpnMenu to click
set connectionStatusItem to (menu item 1 of menu 1 of vpnMenu)
if title of connectionStatusItem is equal to ("Connect " & vpnServiceName) then
tell connectionStatusItem to click
end if
end tell
end tell
end if
end idle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment