summaryrefslogtreecommitdiff
path: root/bin/wifi
blob: 141210a3d49f3576398dac9aeb2b75ec27e1e2fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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