July 2009 Archives
I have an AppleScript that fires occasionally and automatically updates my iChat status to indicate if I’m at home, at work, or wherever. You know, so I don’t have to waste my time on it.
It works by detecting the Wi-Fi base station I’m connected to. But of course, every time Apple updates its OS, it breaks the methods I use.
Under Leopard I use this approach:
system_profiler SPAirPortDataType|grep -e “Current Wireless Network:”|awk ‘{print $4}’
That Terminal command gets wrapped in a “do shell script” command for AppleScript purposes.
But here’s the thing. In a future OS update, Apple has changed the output of the system_profiler SPAirPortDataType
command. Now what it spits out is:
AirPort: Software Versions: Menu Extra: 6.0 (600.22) configd plug-in: 6.0 (600.27) System Profiler: 6.0 (600.9) Network Preference: 6.0 (600.22) AirPort Utility: 5.4.2 (542.23) IO80211 Family: 3.0 (300.20) Interfaces: en0: Card Type: AirPort Extreme (0x14E4, 0x8B) Firmware Version: Broadcom BCM43xx 1.0 (5.10.91.19) Locale: FCC Country Code: US Supported PHY Modes: 802.11 a/b/g/n Supported Channels: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 Wake On Wireless: Supported Status: Connected Current Network Information: Extreme Meadow: PHY Mode: 802.11n BSSID: 0:1c:b3:ae:42:c3 Channel: 11 Network Type: Infrastructure Security: WPA2 Personal Signal / Noise: -58 dBm / -92 dBm Transmit Rate: 130 MCS Index: 15
So, grep/sed/awk terminal wizards, any suggestions on how to update my command-line command to parse that I’m connected to “Extreme Meadow”? And fail gracefully if I’m not connected to any SSID, at which point the entire “Current Network Information” block disappears.
Update
Lots of smart people helped. This seems to work.
do shell script "/System/Library/PrivateFrameworks
/Apple80211.framework/Versions/Current/
Resources/airport -I|
egrep '^[ ]+SSID:'|cut -f2 -d:"