问题
Seriously, I'm embarrassed to even be asking this.
I've got an Applescript that is supposed to build a playlist of a bunch of whole albums. Everything works fine, except for actually adding the tracks to the playlist. Here's the relevant code:
repeat with theAlbum in randAlbums
set these_tracks to (tracks of library playlist 1 whose album is theAlbum)
repeat with the_track in these_tracks
add the_track to playlist thePlaylist (* doesn't work *)
end repeat
end repeat
The error I get is "iTunes got an error: A descriptor type mismatch occurred."
randAlbums is a list of unique album names, and thePlaylist is a playlist that is created earlier in the script.
I've been banging my head against this for what feels like a week and I haven't been able to figure it out. Thanks in advance for any assistance you can offer :)
回答1:
Duplicate is the command you want. Try this:
repeat with theAlbum in randAlbums
duplicate (tracks of library playlist 1 whose album is theAlbum) to thePlaylist
end repeat
Within the iTunes interface add
is used to add a new track to the iTunes library using a file system path, while duplicate
is used to place a reference to an existing track in a playlist.
When the add command is used iTunes will eventually figure out that the track is already part of the library and do what you want, but not before it reads the file's metadata, schedules it for album art retrieval, etc. All of this amounts to a pretty slow operation so if you're using it within a loop for a large number of tracks iTunes will slow to a crawl.
Duplicate performs a native database lookup and adds the results to the playlist all at once so it is very fast.
回答2:
Try:
copy the_track to end of playlist thePlaylist
instead.
回答3:
Try changing that line to:
add (get location of the_track) to playlist thePlaylist
or, if thePlaylist
is already a playlist reference (instead of just the string name of a playlist):
add (get location of the_track) to thePlaylist
回答4:
Applescript is really weird...but checkout the scripts here dougscripts.com
Looks like he uses duplicate and not add when adding to a playlist. I'm looking at the One Song From Each script
Hmmm...how about?
add (a reference to the_track) to playlist thePlaylist
来源:https://stackoverflow.com/questions/531692/applescript-question-adding-tracks-to-playlists