-
Notifications
You must be signed in to change notification settings - Fork 15
/
wifitoggle
executable file
·31 lines (30 loc) · 1.01 KB
/
wifitoggle
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
#!/usr/bin/env bash
# This is a shell script to toggle Wi-Fi power
# Written and tested on Sierra (macOS 10.12.5 and 10.12.6)
# and Fedora 27
case "$OSTYPE" in
darwin*)
CMD="/usr/sbin/networksetup"
# Determine which interface is the Wi-Fi interface
IFACE=$($CMD -listallhardwareports | grep -A1 'Wi-Fi' | awk '/Device/ {print $2}')
# Get the current Wi-Fi power status using networksetup
STATUS=$($CMD -getairportpower $IFACE | cut -d' ' -f4)
# Evaluate current status and toggle power
if [[ $STATUS == 'On' ]]; then
$CMD -setairportpower $IFACE off
elif [[ $STATUS == 'Off' ]]; then
$CMD -setairportpower $IFACE on
fi
;;
linux*)
CMD="/usr/bin/nmcli radio wifi"
# Get the current Wi-Fi power status using nmcli
STATUS=$($CMD)
# Evaluate current status and toggle power
if [[ $STATUS == 'enabled' ]]; then
$CMD off
else
$CMD on
fi
;;
esac