recursive iteration of a subroutine that reruns itself?!!!

Sorry for the title, but I’m at a loss for a more simple/clear subject title :smiley:

Let me explain my goal…
(I’m playing with 10.3.9 & iTunes 5.x)
I’m trying to create a subroutine that will modify a given track list upon user modification. For example, you have a song track list in random order {4,6,3,1,2,5}. The track list is in a repeat loop like…

repeat with i in {4,6,3,1,2,5}
set x to i
play track x of current playlist
delay x amount of time
end repeat

iTunes will play track #4, then #6, etc, until it plays track #5 last, IF you don’t touch the iTunes direction buttons (rwd, ff).Let’s say you don’t like tracks 6 & 3, after track #4 ends you skip over them to listen to track #1. When track #1 finishes playing, instead of going to track #2 (the next track of the playlist), it plays track #6 because of the repeat loop.

I’ve been trying to write a subroutine that would modify the track list (by removing the skipped tracks) and re-inserting the modified track list into the repeat loop. Using my example: original track list {4,6,3,1,2,5} ; listen to track 4; skip tracks 6 & 3; listen to track 1; modified track list {2,5} (songs not yet played).
Now re-insert {2,5} into repeat loop.

I hope my problem makes sense.

I’ll greatly appreciate any help! :cool:

Jacques - awesome! Thanks so much. I was thinking that it would be more complex than that. :smiley:

The following is almost how I want it to perform. I post the script below in case anyone else may find this useful.
–Cheers.


global trk_list
--set trk_list to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
set trk_list to {2, 6, 9, 3, 7, 8, 5, 12, 1, 4, 11, 10, 13}

tell application "iTunes"
	
	repeat until trk_list is {}
		set limit to length of trk_list
		set dummyList to {}
		play track (item 1 of trk_list) of current playlist
		delay 5
		if index of current track is not (item 1 of trk_list) then
			set lst_plyd to index of current track
			repeat with i from 2 to limit
				set this_item to (item i of trk_list)
				if this_item is not lst_plyd then
					copy this_item to the end of dummyList
				end if
			end repeat
			set trk_list to dummyList
			log trk_list
		else
			set trk_list to rest of trk_list
		end if
	end repeat
	
end tell

And here is the final version that will allow you to skip multiple tracks & remove them all from the playlist…


global trk_list
set trk_list to {2, 6, 9, 3, 7, 8, 5, 12, 1, 4, 11, 10, 13}

tell application "iTunes"
	
	repeat until trk_list is {}
		set limit to length of trk_list
		set dummyList to {}
		play track (item 1 of trk_list) of current playlist
		delay 5
		if index of current track is not (item 1 of trk_list) then
			set lst_plyd to index of current track
			repeat with i from 1 to limit
				set this_item to (item i of trk_list)
				if this_item < (item 1 of trk_list) then
					copy this_item to end of dummyList
				else
					if this_item > (index of current track) then
						copy this_item to end of dummyList
					end if
				end if
			end repeat
			set trk_list to dummyList
			log trk_list
		else
			set trk_list to rest of trk_list
		end if
	end repeat
	
end tell

(* using this subroutine, when you skip a track or tracks it will remove those tracks from the master track list & countinue playing the master track list where things left off.
e.g., skip tracks 2,3,4 & listen to track 5 --> new playlist is {6,9,7,8,12,1,11,10,13}
*)