summaryrefslogtreecommitdiff
path: root/bin/wifi
diff options
context:
space:
mode:
Diffstat (limited to 'bin/wifi')
-rwxr-xr-xbin/wifi33
1 files changed, 33 insertions, 0 deletions
diff --git a/bin/wifi b/bin/wifi
new file mode 100755
index 0000000..141210a
--- /dev/null
+++ b/bin/wifi
@@ -0,0 +1,33 @@
+#!/bin/bash -l
+
+set -euo pipefail
+
+is_on() {
+ networksetup -getairportpower en0 \
+ | grep -q ' On'
+}
+
+current() {
+ /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I \
+ | awk -F' SSID: ' '/ SSID: / {print $2}'
+}
+
+action() {
+ if [[ "$1" == "on" ]] && is_on
+ then
+ notify "WiFi status" "Connected to: $(current)"
+ else
+ networksetup -setairportpower en0 "$1"
+ notify "WiFi status" "On, searching for networks..."
+ fi
+}
+
+arg="${1:-''}"
+if [[ "$arg" == "on" ]]; then
+ action on
+elif [[ "$arg" == "off" ]]; then
+ action off
+else
+ >&2 echo "ERROR. Need \"on\" or \"off\" arg."
+fi
+