I’ve got a script that lets me select a playlist. No problem. But sometimes I want to hear an album, instead. Is there a way to get an album list (without repeats)?
I’ve tried this
tell application "iTunes" to set albumList to album of every file track of library playlist 1
set shortAlbumList to {}
repeat with myAlbum in albumList
if shortAlbumList does not contain myAlbum then
set end of shortAlbumList to myAlbum
end if
end repeat
return shortAlbumList
but it “goes to visit the guru” at some point. Meaning, it runs and hangs. I’ve even watched Activity Monitor while it runs, and it pegs the CPU for a few seconds (I have a lot of albums) then the CPU usage drops but the Script Editor never finishes the script. What’s up with that?
DUH. Answered my own quesiton:
tell application "iTunes" to set albumList to album of every file track of library playlist 1
set shortAlbumList to {}
repeat with myAlbum in items of albumList
if (shortAlbumList does not contain myAlbum) and (length of myAlbum is not 0) then
set shortAlbumList to shortAlbumList & myAlbum
end if
end repeat
set theAlbum to choose from list shortAlbumList
Note “items of albumList” not “albumList”. DUH.
I believe the problem with Kevin’s script is that it has to get the items
on every loop.
Jacques,
Thanks! That’s much faster!
Bruce - Funny how the way you phrase things makes a difference, eh? Although what I wrote looks like “standard” applescript, it doesn’t perform well. We could write up a whole series of Scriptwire articles about stuff like that.