iTunes track change handler??

I’ve written a script that creates iPod notes from a track’s lyrics and transfers them to a subfolder on my iPod. I’d like a way to automatically run this script on the playing track each time the track changes. Is there any sort of “track change handler” that allows me to “do this when the playing track changes”? Yes, I’ve read the iTunes scripting dictionary, and nothing there seems to match my needs.

you’ll have to use an idle routine that looks for a change in the current track

Yeah, that’s pretty much what I was asking for help with–I was probably just using the wrong terminology. I’m still learning about AS, and this site is one of my avenues of learning.
So although I appreciate your reply, I think you just sort of rephrased my own question.

I’m not an AS master like many here, but this is what I did. Ask if you need me to clarify.

(* This subroutine monitors user modification of iTunes playback. It will check track name & player position every 5 seconds. If a user skips a track or skips forward/backward in a track it will rerun this subroutine & get new lyrics (if track has been changed) *)
on alter_playbk()
	tell application "iTunes"
		set tme to (duration of current track)
		set pos to player position
		set remain to tme - pos
		set rpt_num to round ((remain - 10) / 5)
		set xyz to 0
		log rpt_num
		repeat rpt_num times
			set y to name of current track
			set z to player position
			delay 5
			if name of current track is not equal to y then
				display dialog "Track has been changed"
				exit repeat
				set pos_buff to {z + 5, z + 6, z + 7, z + 8, z + 9}
				if {player position} is not in pos_buff then
					display dialog "Leave the slider alone"
					exit repeat
				end if
			end if
		end repeat
	end tell
end alter_playbk

Thanks bonkers. 1 question: How do I put your subroutine to use?
Here’s what I’ve got–I’ve got the script that I originally posted in the linked thread, which just copies any existing song lyrics of the playing/selected track onto my iPod as a note. I want to leave the script as-is, so I can use it as desired as a standalone script from within iTunes. But I also want to be able to run another script in the background when I so desire that will just monitor iTunes for track changes (as yours apparently does) and, when the track changes, call my first script. Thus, each time the track changes, it’s song lyrics will automatically be copied to my iPod.
Since I’m a novice, I’m not really sure how to use your subroutine to accomplish this. Do I just make your subroutine script into a stay-running app-bundle, and run it with iTunes? If subroutines can’t be used this way, then how do I incorporate it into a separate standalone stay-running script?
Thanks alot for your help!

yes, you can save it as a stay-open application. (it is written as a subroutine because I thought you were going to incorporate it into your other script)

just change “on alter_playbk()” → “on idle”
& “end alter_playbk” → “end idle”

then save as a stay-open app.

iTunes needs to be up & running before you give this script a try…

An idle handler is a great way to unobtrusively monitor a process because idle events are managed by the system and therefore don’t necessarily lock up your processor the way conventional repeat loops or the ‘delay’ command often do. Here’s a simple script I wrote that checks every five seconds to see if the current track has changed, and if so announces the new artist/track using text-to-speech.

property played : reference -- important, put this at the top of the script

on idle
		tell application "iTunes" to tell current track to if it is not played then
			copy it to played
			say artist & ". " & name
			my subroutine()
		end if
	end try
	return 5 -- seconds later
end idle

on subroutine()
	-- do something
end subroutine