Set iChat status by Network Location (revisited)

May 14, '04 09:30:00AM

Contributed by: mattshep

A previous hint was posted offering a script for updating your iChat status based on your subnet or SSID. The script worked as a standalone hidden application. But since many users already use iChatStatus to display song titles from iTunes and such, I've reworked the original script so it too could be chosen from iChatStatus.

Read the rest of the article for the script and process to get it working...

  1. Download and install iChatStatus.
  2. Copy this following code into Script Editor. Update the networks with your own personal settings and save it to "Location by Network.scpt"
    
    -- Use MakeNetwork(Subnet, AirportName, StatusMessage) to add your own networks
    MakeNetwork("192.168.1.", null, "I'm at home")
    MakeNetwork(null, "WireFree", "I'm at work")
    
    -- AppleScript
    property Networks : {}
    
    on MakeNetwork(pSubnet, pAirportName, pStatusMessage)
     
     script Network
      property AirportName : pAirportName
      property Subnet : pSubnet
      property StatusMessage : pStatusMessage
     end script
     
     set Networks to Networks & Network
     
     return Network
     
    end MakeNetwork
    
    tell application "System Events"
     
     set EthernetIPAddress to do shell script ¬
      "ifconfig en0 | awk '/inet / {print $2}'"
     set AirportIPAddress to do shell script ¬
      "ifconfig en1 | awk '/inet / {print $2}'"
     set AirportName to do shell script ¬
     "system_profiler SPAirPortDataType|awk -F\": \" '/Current Wireless Network/{print $2}'"
     
     repeat with Network in Networks
      if Subnet of Network is not null then
       if EthernetIPAddress begins with Subnet of Network then
        return StatusMessage of Network
       end if
       
       if AirportIPAddress begins with Subnet of Network then
        return StatusMessage of Network
       end if
      end if
      
      if AirportName of Network is not null then
       if AirportName is equal to AirportName of Network then
        return StatusMessage of Network
       end if
      end if
      
     end repeat
     
     return "Error: No match"
     
    end tell
  3. Put the "Location by Network.scpt" file in ~/Application Support/iChatStatus
  4. Open System Prefs. Go to iChatStatus, activate it, choose "Location by Network. scpt", set the prefix to empty and click update.
Enjoy!

Comments (8)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040512170804933