Skip to content

Instantly share code, notes, and snippets.

@gadelkareem
Last active November 20, 2019 12:26
Show Gist options
  • Save gadelkareem/abefb1879984a02efb4d13a3838a89f3 to your computer and use it in GitHub Desktop.
Save gadelkareem/abefb1879984a02efb4d13a3838a89f3 to your computer and use it in GitHub Desktop.
Auto Reconnect a VPN for k8s on OSX
on idle
set vpnServiceName to "VPN NAME"
set connected to ""
delay 10
try
set connected to do shell script "/usr/local/bin/kubectl get namespace --request-timeout 5s &> /dev/null && echo 1"
on error errorMessage number errorNumber
end try
log connected
if connected is not equal to "1" 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