forked from rimar/wifi-location-changer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locationchanger
executable file
·38 lines (32 loc) · 1.09 KB
/
locationchanger
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
#!/bin/bash
# automatically change location settings based on SSID
exec &>/usr/local/var/log/locationchanger.log
# redirect all IO to /dev/null (comment this out if you want to debug)
# exec 1>/dev/null 2>/dev/null
# pause before we fetch data
sleep 2
# get current SSID
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | grep ' SSID:' | cut -d ':' -f 2 | cut -c 2-`
# get location information
LOCATION_NAMES=`scselect | tail -n +2 | cut -d "(" -f 2 | cut -d ")" -f 1`
CURRENT_LOCATION=`scselect | grep " \* " | cut -d "(" -f 2 | cut -d ")" -f 1`
# check for office SSIDs
if [[ "$SSID" =~ "GrayLoon" ]]; then
NEW_LOCATION="Gray Loon"
else
# use Other if no matching SSID found
if echo Other | grep -q "$LOCATION_NAMES"; then
NEW_LOCATION=Other
else
echo "Other location was not found!"
echo "The following locations are available:"
echo "$LOCATION_NAMES"
fi
fi
# switch the location
if [ "x$NEW_LOCATION" == "x$CURRENT_LOCATION" ]; then
echo "Nothing to do"
else
echo "Changing to $NEW_LOCATION"
scselect "$NEW_LOCATION"
fi