Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Update Location on Wake' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Update Location on Wake
Authored by: colter on Jan 26, '05 04:44:39PM
After combining several of the hints here, this is what I finally got working for me: First, I installed SleepWatcher so that I can trigger the script when I wake from sleep. Given how I work, that's enough for me. Then I created /usr/local/bin/update-location.sh:

#!/bin/sh

#get the name of the wireless network you are on
#shown on two lines; should be one with a space
wlan=`/usr/sbin/system_profiler SPAirPortDataType | 
        awk -F": " '/Current Wireless Network/{print $2}'`

#look up the status
location=`grep -i "IT Airport" .wlans | awk -F"\t" '{print $2}'`
if [ "$location" = "" ] 	# If we didn't find the network
then
	location="Automatic"	# Default to Automatic
fi

#update the location
newloc=`/usr/sbin/scselect "${location}" | sed 's/^.*(\(.*\)).*$/\1/'`

echo ${newloc}

#exit with error if the location didn't match what you expected
if [ "${location}" != "${newloc}" ]
then
    exit 1
fi

exit 0
Then in ~/.wakeup

#!/bin/sh

/usr/local/bin/update-location.sh
All this does is call the above script when the computer wakes. This way, you can easily add other tasks while keeping the location-switching code separate. I wanted the list of locations to be easily editable, so I created a tab-delimited file at ~/.wlans

Home Airport\tAutomatic
Work Airport\tWork Location
tmobile\tStarBucks
It's just a list of wireless network - location pairs separated by a tab. If the update-locations.sh script doesn't find an entry, it will default back to Automatic. This works for me, ymmv. Like I said, this is mainly a conglomeration of other hints, but I thought I'd pass it on for posterity.

[ Reply to This | # ]
Update Location on Wake
Authored by: hintbw on Mar 25, '05 02:31:20PM

I found I had to make the following change in the script (see below) in order for it to work for me. It is an excellent script, now I don't ever have to remember to change locations.

The one other element to the script that I would like to add is for it to change locations based on ip address (i.e. have it check for a wired ethernet ip address and set the location depending on the ip address it is currently getting, if it doesn't find a wired ip address to fall back to the current script to check for a wireless network and set the location accordingly.

Thanks for the script Colter

Here's the original code


#look up the status
location=`grep -i "IT Airport" .wlans | awk -F"\t" '{print $2}'`

Here's what I had to change it to get it to work for me.


#look up the status
location=`grep -i "$wlan" .wlans | awk -F"\t" '{print $2}'`


[ Reply to This | # ]