Skip to content

Instantly share code, notes, and snippets.

@draftcode
Created January 11, 2009 05:32
Show Gist options
  • Save draftcode/45650 to your computer and use it in GitHub Desktop.
Save draftcode/45650 to your computer and use it in GitHub Desktop.
Change location following SSID
#!/bin/bash
## Settings
# locations (use to be used Location name here)
ATHOME="home"
ATWORK="titech"
# detect HOME
ATHOME_SSID="home_router_ssid"
ATWORK_SSID="titech-pubnet"
## {{{ Codes
exec 1>/dev/null 2>/dev/null
SSIDs=`/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -s\
| tail -n +2 | awk '{print $1}'`
Work=`echo $SSIDs | grep $ATWORK_SSID`
Home=`echo $SSIDs | grep $ATHOME_SSID`
netloc=`scselect 2>&1 | egrep '^ \* ' | sed 's:.*(\(.*\)):\1:'`
newloc=netloc # default behavior
if [ -n "$Work" ]; then
LOCATION=$ATWORK
REASON=SSID
echo "export ALL_PROXY=proxy.noc.titech.ac.jp:3128" > $HOME/.zsh/proxy
fi
if [ -n "$Home" ]; then
LOCATION=$ATHOME
REASON=SSID
echo "export ALL_PROXY=" > $HOME/.zsh/proxy
fi
if [ -z "$LOCATION" ]; then
LOCATION=$ATHOME
REASON=Fallback
echo "export ALL_PROXY=" > $HOME/.zsh/proxy
fi
case $LOCATION in
$ATWORK )
newloc=$ATWORK
;;
$ATHOME )
newloc=$ATHOME
;;
esac
if [ $newloc != $netloc ]; then
scselect $newloc
echo `date` "Location: $LOCATION - $REASON" >> $HOME/.locationchanger.log
`/usr/local/bin/growlnotify -m "Location: $LOCATION - $REASON" "Location changed"`
fi
exit 0;
#}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment