This trick is supposed to enable faster interation of large lists, however if you compare the first script with the second script, the first script runs faster.
Or perhaps I am not applying the trick correctly.
tell application "iTunes"
--construct a list of tracks to be transcoded
set tracklist to {}
set alactrack to tracks of playlist "Library" whose kind is "Apple Lossless audio file" and enabled is true
repeat with trackn in alactrack
if ((count of (tracks of playlist "Library" whose (name is (get name of trackn)) and (time is (get time of trackn)) and kind is "AAC audio file")) = 0) then set end of tracklist to trackn
end repeat
if length of tracklist > 0 then
set currentencoder to current encoder
set current encoder to encoder "AAC Encoder"
with timeout of 24 * 60 * 60 seconds
set convertedtracks to convert tracklist
end timeout
repeat with trackn in tracklist
set enabled of trackn to false
end repeat
end if
end tell
tell application "iTunes"
--construct a list of tracks to be transcoded
set tracklist to {}
set alactrack to a reference to tracks of playlist "Library" whose kind is "Apple Lossless audio file" and enabled is true
repeat with trackn in alactrack
if ((count of (tracks of playlist "Library" whose (name is (get name of trackn)) and (time is (get time of trackn)) and kind is "AAC audio file")) = 0) then set end of tracklist to trackn
end repeat
if length of tracklist > 0 then
set currentencoder to current encoder
set current encoder to encoder "AAC Encoder"
with timeout of 24 * 60 * 60 seconds
set convertedtracks to convert tracklist
end timeout
repeat with trackn in tracklist
set enabled of trackn to false
end repeat
end if
end tell