iChat Knows Where I Am

Today's Best Tech Deals

Picked by Macworld's Editors

Top Deals On Great Products

Picked by Techconnect's Editors

There is nothing more annoying than getting an instant message from someone wondering why you're at home in the middle of the day, because you forgot to change your iChat status from "at home" to "at the office." Okay, maybe there are a few things more annoying.

Anyway, I realized that my PowerBook knows where it is, because it sees the AirPort Base Stations that are around me. At home, it locks onto my home AirPort network, and at work, it locks on to the work network. So I decided to write an AppleScript that remembered to set my status on iChat AV, even when I forgot. It finds out what Base Station my PowerBook is attached to, and based on that, it sets my iChat AV status. If it doesn't recognize where it is, it does nothing. And it checks to see whether iChat was running or not when it launched, so that it can get iChat back out of the way again once it's finished.

Now, as far as I can tell, the only scriptable application that knows about AirPort connections is Internet Connect. So this script opens up Internet Connect, which is annoying, but apparently a necessary evil.

Anyway, it does work. If someone knows a better way of doing this, I'd love to hear it. Better yet, I'll post it here. ( UPDATE: Jeff Veen points out this illuminating tip at MacOSXHints.com about the system_profiler command-line utility, which lets you get at your Base Station status without launching Internet Connect. I've updated the script accordingly.)

(To execute it, I just set up a cron job [using CronniX ] to run this script at times when I'm likely to be newly at home or work. I get a lot fewer complaints from my iChat buddies now.)

( UPDATE: The good folks at MacChampion suggested I try out their Scenario utility, a script launcher that can be set to execute scripts when a PowerBook wakes up. It works like a charm!) global iChatLife
tell application "System Events" to set iChatLife to name of processes contains "iChat"

set BaseStation to the (do shell script "system_profiler SPAirPortDataType|awk -F": " '/Current Wireless Network/{print $2}'")
--Uses the system_profiler command-line utility to tell us the current base station name

if the BaseStation is "Office Base Station" then
    setStatus("at the office")
else if the BaseStation is "Home AirPort" then
    setStatus("at home")
     -- do nothing
end if

on setStatus(statusString)
       --Look, Ma, a subroutine to set iChat AV Status!
         tell application "iChat"
         set status message to statusString
         if iChatLife is false then
             tell application "iChat" to quit
         end if
     end tell     
end setStatus

Also, check out Jon Bauman's take on this same topic at Mac OS X Hints.

Note: When you purchase something after clicking links in our articles, we may earn a small commission. Read our affiliate link policy for more details.
Shop Tech Products at Amazon