Last active
November 20, 2019 12:26
-
-
Save gadelkareem/abefb1879984a02efb4d13a3838a89f3 to your computer and use it in GitHub Desktop.
Auto Reconnect a VPN for k8s on OSX
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
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