-
Notifications
You must be signed in to change notification settings - Fork 0
/
swns
executable file
·53 lines (40 loc) · 1.32 KB
/
swns
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
SERVICES=`networksetup -listnetworkserviceorder \
| grep -B1 "Port: Wi-Fi" \
| grep -v "^--$" \
| grep -v "Port: Wi-Fi" \
| sed 's/^(.*)\ //' \
| awk '{print "[" NR "] " $0}'`
echo 'Choose a network service you want to enable the following:'
echo
echo "$SERVICES" | xargs -I{} echo " {}"
echo
set -o emacs
function inputNumberLoop() {
local switchServiceFunc="networksetup -setnetworkserviceenabled "
read -e -p 'Which number (0 to quit)? ' -- SELECTED_NUM
if [[ "$SELECTED_NUM" = "0" ]]; then
echo "Quit."
exit
fi
local SELECTED_SERVICE=`echo "$SERVICES" | grep -e "^\[$SELECTED_NUM\] .*$" | sed 's/\[[0-9]*\] //'`
if [[ $SELECTED_SERVICE == "" ]]; then
echo "Wrong number."
inputNumberLoop
else
# Disable all services.
echo "$SERVICES" | sed 's/\[[0-9]*\] //' | xargs -I{} $switchServiceFunc {} off
# Enable the specific one service that the user chose.
$switchServiceFunc "$SELECTED_SERVICE" on
echo "You chose \"$SELECTED_SERVICE\"."
fi
}
inputNumberLoop
echo
echo "Restarting Wi-Fi connection ..."
networksetup -setairportpower en0 off
networksetup -setairportpower en0 on
echo "Restarting Wi-Fi connection done."
echo
echo "Current Wi-Fi service order ((*) means disabled):"
networksetup -listnetworkserviceorder | grep -B1 "Port: Wi-Fi" | grep -v "^--$"