Last active
November 17, 2024 12:26
-
-
Save zored/4a4b4bab855e29167abd3db9fa475bba to your computer and use it in GitHub Desktop.
Toggle TunnelBear from macOS console. Enable or disable TunnelBear VPN with CLI. Compatable with TunnelBear 3.8.0. Based on SH and AppleScript.
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
#/usr/bin/env bash | |
# Include this file in `~/.bash_profile` with `source /path/to/tunnelbear-toggle.sh`. | |
# Toggle TunnelBear activity. | |
# | |
# Example usage: | |
# `tunnelbear-toggle` | |
# `tunnelbear-toggle 1` | |
tunnelbear-toggle () | |
{ | |
local enable=${1:-''} expectedState=''; | |
case ${enable} in | |
'1') | |
expectedState="Disconnected" | |
;; | |
'0') | |
expectedState="Connected" | |
;; | |
'') | |
expectedState='' | |
;; | |
*) | |
echo 'Enable argument must be empty / 0 / 1.' &> 2; | |
return 1 | |
;; | |
esac; | |
osascript <<AS | |
set expectedState to "$expectedState" | |
tell application "System Events" | |
tell process "TunnelBear" | |
set toggleAppButton to (menu bar item 1 of menu bar 2) | |
click toggleAppButton | |
set mainWindow to (window "Window") | |
tell mainWindow | |
set toggleConnectionElement to (UI element 2) | |
set state to (value of static text 0) | |
if ((expectedState is "") or (state is expectedState)) then | |
click toggleConnectionElement | |
click toggleAppButton | |
else | |
log "Expected state is: '" & expectedState & "', but got: '" & state & "'." | |
click toggleAppButton | |
error number 1 | |
end if | |
end tell | |
end tell | |
end tell | |
AS | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mistyped "tunnelblick" with "tunnelbear" and ended up here 😆
If anyone is looking for tunnelBLICK solution then it's just easy (in case of 1 VPN configuration at least):