An Obsession with Everything Else

http://www.derrickschneider.com/atom.xml

Tuesday, October 24, 2006

iTunes Now Playing in iChat

If you're a relic like me who has not yet upgraded to 10.4, here's an AppleScript that will set your iChat status message to the currently playing track in iTunes (the feature's built in to 10.4). Just save it as an application that stays open.


As always, AppleScript frustrated and annoyed me, but I got the script working and it seems to do pretty well. There's no noticeable lag from the once-a-second check. You can see my ancient AppleScript roots in my concerted effort to minimize the number of Apple Events I send between the applications. I don't think this is a problem in Mac OS X, but it used to be the case that Apple Events were put on the normal event queue, which was polled every sixtieth of a second. Thus, good scripters worked hard to grab the maximum amount of information in one event, rather than grabbing each piece one at a time (for instance, getting a single record from FileMaker instead of field 1, field 2, etc.). The piecemeal approach would slow big scripts to a crawl.




on run
tell application "iChat"
set originalMsg to the status message
end tell
set curTrack to ""
repeat

tell application "iTunes"
if player state is playing then
set curTrackObj to current track
set newCurTrack to (the name of curTrackObj & " - " & the artist of curTrackObj)
if newCurTrack is not equal to curTrack then
set curTrack to newCurTrack
tell application "iChat"
set status message to curTrack
end tell
end if
else
tell application "iChat"
set status message to originalMsg
end tell
end if
end tell
delay 1
end repeat
end run

0 Comments:

Post a Comment

<< Home