(* Now Playing in Adium v1.0 by Adam Nolley Based on Now Playing in iChat AV v1.8.1 written by Doug Adams Get more free AppleScripts for iTunes and help writing your own: http://www.malcolmadams.com/itunes/ v1.8.1 -- truncates long entries to fit iChat AV's 42 character limit in status message -- change "unidentifiable" to "unknown" -- status message_prefix changes for CD track, file track, or stream v1.8 -- won't run iTunes if it isn't already running -- uses iTunes 4.1 "current stream track" info if available -- restores status of iChat when quit v1.7 -- fixed quit if iChat and ot iTunes not running (d'oh!) -- fixed crash when radio stream playing v1.6 - uses unicode BEAMED EIGHTH NOTES & space as message_prefix1 v1.5 - displays iTunes track only when iChat status is "Available" - behaves better when iTunes is not running - updates status if current track info changes - sub-routined "check System Events" routine - sub-routined poll_itunes routine *) -- the following strings precede the track info in iChat status. -- these are Unicode strings -- you can change them, if you like, just make sure -- text is always inside "" property message_prefix1 : «data utxt266B0020» -- BEAMED EIGHTH NOTES --property message_prefix1 : "Now Playing: " -- BEAMED EIGHTH NOTES property message_prefix2 : «data utxt29BF0020» -- CD (CIRCLED BULLET) --property message_prefix2 : "Now Playing: " -- CD (CIRCLED BULLET) property message_prefix3 : «data utxt26220020» -- STREAM (RADIOACTIVE SIGN) --property message_prefix3 : "Now Playing: " -- STREAM (RADIOACTIVE SIGN) property message_prefix4 : «data utxt266B0020» -- spare not used yet, same as 1 --property message_prefix4 : "Now Playing: " -- spare not used yet, same as 1 -- this string is displayed when iTunes is not playing -- you can change it, if you like, just make sure -- text is always inside "" property not_listening_message : "Nothing" -- do not change these property theT : null property art : null property nom : null property cur_message : "" property curTime : null property maxTime : null global myMessage, message_prefix set x to my substitute() display dialog ((count x) as Unicode text) & ": " & x as Unicode text on substitute() tell application "System Events" set iTunes to ((application processes whose (name is equal to "iTunes")) count) end tell if iTunes is greater than 0 then tell application "iTunes" try if player state is playing then set theNewT to current track if theNewT is not theT or (nom is not theNewT's name or art is not theNewT's artist) or cur_message does not start with message_prefix then copy theNewT to theT tell me to fig_tags() -- comment out the next line to skip truncate feature --tell me to truncate(nom, art) set curTime to player position --set maxTime to track duration tell current track set maxTime to duration end tell set temp to (curTime mod 60) if temp ? 9 then set temp to "0" & temp end if set curTime to (round (curTime div 60) rounding down) & ":" & temp set maxTime to (round (maxTime div 60) rounding down) & ":" & (round (maxTime mod 60)) set myMessage to myMessage & " (" & curTime & "/" & maxTime & ")" end if else copy message_prefix1 to message_prefix set myMessage to not_listening_message end if end try end tell else -- If iTunes isn't running, then display this message. copy message_prefix1 to message_prefix set myMessage to not_listening_message end if return (message_prefix as Unicode text) & " Now Playing: " & myMessage end substitute to fig_tags() -- initialize; used as two parts of status message set {nom, art} to {"", ""} tell application "iTunes" if class of theT is URL track then copy message_prefix3 to message_prefix -- radioactive tell theT try if name is not "" and name is not missing value then set nom to name else set nom to "unknown" end if end try end tell -- if 4.1+ stream... try if (get current stream title) is not missing value then if (get current stream title) contains " - " then set {art, nom} to my TextToList((get current stream title), " - ") else if (get current stream title) contains "-" then set {art, nom} to my TextToList((get current stream title), "-") else set nom to (get current stream title) end if --set art to " by " & art end if end try else -- is file, cd, device, or other track if class of theT is audio CD track then copy message_prefix2 to message_prefix -- CD else copy message_prefix1 to message_prefix -- 8ths end if tell theT try if artist is not "" then set art to artist else set art to "unknown artist" end if end try try if name is not "" then set nom to name else set nom to "unknown song" end if end try end tell end if end tell if art is not "" then set myMessage to (art & " - " & nom) else set myMessage to (nom) end if end fig_tags to truncate(nom, art) set lennom to (count nom) set lenart to (count art) set totlen to (lenart + lennom) if art is not "" then set myMessage to (art & " - " & nom) else set myMessage to (nom) end if end truncate --============================================ on TextToList(theText, theDelimiter) set saveDelim to AppleScript's text item delimiters try set AppleScript's text item delimiters to {theDelimiter} set theList to every text item of theText on error errStr number errNum set AppleScript's text item delimiters to saveDelim error errStr number errNum end try set AppleScript's text item delimiters to saveDelim return (theList) end TextToList on ListToText(theList, theDelimiter) set saveDelim to AppleScript's text item delimiters try set AppleScript's text item delimiters to {theDelimiter} set theText to theList as text on error errStr number errNum set AppleScript's text item delimiters to saveDelim error errStr number errNum end try set AppleScript's text item delimiters to saveDelim return (theText) end ListToText