views:

808

answers:

4

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 :)

A: 

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
epatel
I've looked over *many* of the scripts on Doug's site for inspiration and/or a clue as to how to solve this, but to no avail. thanks though :)
inkedmn
Yep, I've actually got that script open, too. Unfortunately, 'duplicate' gives me the same error :\
inkedmn
A: 

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
Miles
When I do that, I get this error:"iTunes got an error: alias \"Macintosh HD:Users:inkedmn:Music:iTunes:iTunes Music:Vision Of Disorder:For The Bleeders:01 Choke.mp3\" doesn’t understand the add message."Any other ideas? Thanks!
inkedmn
+2  A: 

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.

Matt Stevens
A: 

Try:

copy the_track to end of playlist thePlaylist

instead.

iayork