(* This script was originally written by Aaron Harnly, November 14, 2001. Updated by Doug Adams, v2.0, January 2, 2012. Modified for LCD functionality by Jesse Schooff, Feb 2014 *) property idle_time : 2 -- idle_time determines how often, in seconds, -- the script will check for a new track being played. -- Shorter intervals will place the announcement closer -- to the start of songs, but incur a heavier load on the system. global previous_track global previous_artist global previous_album global myPort on run -- The first moment we run the app, do an announcement. -- This will launch iTunes if it isn't already open, -- but will not start it playing. -- After that, we loop & check for iTunes to play a new song. tell application "iTunes" set previous_track to "" try set previous_track to the current track end try set previous_artist to "" -- set to null so that we'll announce it. set previous_album to "" -- set to null so that we'll announce it. end tell my announce() idle end run on idle repeat if application "iTunes" is not running then exit repeat tell application "iTunes" try if (previous_track is not equal to the current track) then my announce() end if end try end tell delay idle_time end repeat end idle on announce() tell application "iTunes" if (the player state is not playing) then -- don't do anything unless iTunes is playing. return end if set current_track to the current track set track_name to the name of the current_track set track_artist to the artist of the current_track set track_album to the album of the current_track set previous_track to current_track -- We keep track of the last track we announced, -- so that while idling we can check to see if -- iTunes has started playing a new track. -- We also keep track of the previous artist and album, -- so we don't repeat those needlessly next time. set previous_artist to the track_artist set previous_album to the track_album end tell tell application "CoolTerm" -- Truncate track data to fit screen if length of track_name > 15 then set track_name to text 1 thru 15 of track_name end if if length of track_artist > 15 then set track_artist to text 1 thru 15 of track_artist end if if length of track_album > 15 then set track_album to text 1 thru 15 of track_album end if if Connect (WindowID (0)) then set w to WindowID (0) delay 1 set hexCtrl to Hex2Str ("FE 58") Write {w, hexCtrl} set hexCtrl to Hex2Str ("FE 52") Write {w, hexCtrl} WriteLine {w, track_artist} Write {w, track_name} else display alert ("Device Not Connected") end if # Close the port Disconnect w end tell end announce