Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 78 lines (59 sloc) 1.95 KB
#!/bin/bash
# automatically change configuration of Mac OS X based on location
# author: Rocco Georgi <rocco@pavingways.com>
# version: 0.4.0
# original author: Onne Gorter <o.gorter@gmail.com>
# url: http://tech.inhelsinki.nl/locationchanger/
# version: 0.4
# redirect all IO to a logfile
mkdir -p /usr/local/var/log
exec &>/usr/local/var/log/locationchanger.log
# redirect all IO to /dev/null (comment this in if you don#t want to write to logfile)
#exec 1>/dev/null 2>/dev/null
# get a little breather before we get data for things to settle down
sleep 2
# get SSID
SSID=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | awk '/ SSID:/ {print $2}'`
echo `date` "New SSID found: $SSID"
# empty location var
LOCATION=
# LOCATIONS
# (use to be used Location name here)
# =============================================
Location_Automatic="Automatic"
Location_Home="Home"
Location_Work="Company Intranet"
# SSIDS
# =====
SSID_TelekomPublic=Telekom
SSID_Home=HomeSSID
SSID_Work=WorkSSID
# SSID -> LOCATION mapping
case $SSID in
$SSID_TelekomPublic ) LOCATION="$Location_Automatic";;
$SSID_Home ) LOCATION="$Location_Home";;
$SSID_Work ) LOCATION="$Location_Work";;
# ... add more here
esac
REASON="SSID changed to $SSID"
# still didn't get a location -> use Location_Automatic
if [ -z "$LOCATION" ]; then
LOCATION="$Location_Automatic"
REASON="Automatic Fallback"
fi
# change network location
scselect "$LOCATION"
case $LOCATION in
$Location_Automatic )
osascript -e 'display notification "Network Location Changed to Automatic" with title "Network Location Changed"'
;;
$Location_Work )
osascript -e 'display notification "Network Location Changed to Work" with title "Network Location Changed"'
;;
$Location_Home )
osascript -e 'display notification "Network Location Changed to Home" with title "Network Location Changed"'
;;
# ... add more here
esac
echo "--> Location Changer: $LOCATION - $REASON"
exit 0
You can’t perform that action at this time.