-
-
Save alyssais/fea9ff6bcf7955b7f7a5e64656d611aa to your computer and use it in GitHub Desktop.
A tiny command line interface to Viscosity
This file contains 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 | |
run_list() { | |
osascript <<OSA | |
tell application "Viscosity" | |
repeat with theConnection in connections | |
set theName to name of theConnection | |
set theState to state of theConnection | |
log theName & ": " & theState | |
end repeat | |
end tell | |
OSA | |
} | |
run_connect() { | |
if [ "$#" -eq 0 ]; then | |
osascript -e 'tell application "Viscosity" to connectall' | |
else | |
while connection="$1"; shift; do | |
osascript -e "tell application \"Viscosity\" to connect \"$connection\"" | |
done | |
fi | |
} | |
run_disconnect() { | |
if [ "$#" -eq 0 ]; then | |
osascript -e 'tell application "Viscosity" to disconnectall' | |
else | |
while connection="$1"; shift; do | |
osascript -e "tell application \"Viscosity\" to disconnect \"$connection\"" | |
done | |
fi | |
} | |
run_help() { | |
echo "Usage:" | |
echo " $(basename "$0") [list] # List available VPNs" | |
echo " $(basename "$0") connect [VPN [...]] # Connect to specified VPNs (or all)" | |
echo " $(basename "$0") disconnect [VPN [...]] # Disconnect from specified VPNs (or all)" | |
} | |
run_version() { | |
echo "vpn 1.0.0" | |
} | |
main() { | |
local command="$1" | |
shift | |
case "$command" in | |
list | "" ) run_list ;; | |
connect ) run_connect ;; | |
disconnect ) run_disconnect ;; | |
-h | --help ) run_help ;; | |
-v | --version ) run_version ;; | |
*) | |
echo "$(basename "$0"): unknown command: $command" 1>&2 | |
exit 1 | |
;; | |
esac | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome - thank you!
I had to make one tiny tweak on GNU bash, version 5.1.16(1)-release (x86_64-apple-darwin21.1.0)
It was trying to start ALL of viscosity's connections, so I added
$@
to the connect/disconnect commands.