iTunes: Which Song Do I Have the Most Copies Of?

Hi, I’m trying to make an applescript to search through my iTunes library and find out which song i have the most copies of. Currently this is all i have (but it doesn’t work correctly):


tell application "iTunes"
	activate
	copy (a reference to library playlist "Library") to myPlaylist
	set all_tracks to the number of myPlaylist's tracks
	set temptrack to 1
	set maxtrack to 1
	set maxname to ""
	repeat with i from 1 to (all_tracks - 1)
		set this_track to the name of track i of myPlaylist
		set next_track to the name of track (i + 1) of myPlaylist
		if this_track does not contain next_track or next_track does not contain this_track then
			if temptrack is greater than maxtrack then
				set maxtrack to temptrack
				set temptrack to 1
				set maxname to this_track as string
			end if
		else
			set temptrack to (temptrack + 1)
		end if
	end repeat
	display dialog "You have the mist copies of " & maxname & " in your Library"
end tell

Thanks in advanced…any suggestions would be great!

Jake

Try this:


tell application "iTunes"
	set the_list to name of (every track in library playlist "Library")
	set the_list to my shrink(the_list)
	repeat with the_name in the_list
		set the_amounts to the_amounts & (count of (every track whose name is the_name in library playlist "Library"))
	end repeat
	set the_most_repeated to my search_position_of_highest_number_in_list(the_amounts)
	set the_most_repeated_song to (item the_most_repeated of the_list)
end tell

to shrink(some_list) -- this routine takes out any repeated items off a list.
	set shrinked to {item 1 of some_list}
	repeat with i from 2 to (count of some_list)
		if (item i of some_list) is not in (contents of shrinked) then set shrinked to (shrinked & (item i of some_list))
	end repeat
	return shrinked as list
end shrink

Now all you have to do is figure out a routine that searches a list an returns the position of the highest number in that list (should not be so dificult). I’ll get on it but it’s late and I’m sleeping here!! Anyway, you are to decide if there are two songs with the same amount of copies. BTW, this only works if “song names” are identical (exactly the same, case sensitve, etc.). Hope it’s what you wanted, I wasn’t sure. One more thing… I haven’t tested it… sorry ! It should work anyway, it’s not complicated.