Skip to content

Instantly share code, notes, and snippets.

@coneybeare
Last active December 12, 2025 14:22
Show Gist options
  • Select an option

  • Save coneybeare/fb9481b2c1fb0d90f40b30fce4c68ac7 to your computer and use it in GitHub Desktop.

Select an option

Save coneybeare/fb9481b2c1fb0d90f40b30fce4c68ac7 to your computer and use it in GitHub Desktop.
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 "127.0.0.1"
set shellScriptCommands to {¬
"dig +short myip.opendns.com @resolver1.opendns.com", ¬
"dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'\"' '{ print $2}'", ¬
"curl ifconfig.me", ¬
"curl -s http://checkip.dyndns.org/ | grep -o \"[[:digit:].]\\+\"", ¬
¬
""}
repeat with shellScriptCommand in shellScriptCommands
try
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
@its-me-steve
Copy link

Hello. I cant seem to get this to work in MacOS tahoe. It still gives me error that it can't allow assistive access. Do you have any tips

@coneybeare
Copy link
Author

I stopped using this and now use wireguard app, works seamlessly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment