7

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

Patrick Cuff's user avatar

Patrick Cuff

30.1k12 gold badges70 silver badges95 bronze badges

asked Feb 10, 2009 at 9:44

brettkelly's user avatar

0

10

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.

answered Feb 10, 2009 at 15:00

Matt Stevens's user avatar

Comments

1

Try:

copy the_track to end of playlist thePlaylist

instead.

answered Feb 14, 2009 at 0:59

iayork's user avatar

Comments

0

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

answered Feb 10, 2009 at 9:55

Miles's user avatar

1 Comment

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!

0

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

answered Feb 10, 2009 at 9:51

epatel's user avatar

epatel

46.1k17 gold badges113 silver badges145 bronze badges

3 Comments

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

Yep, I've actually got that script open, too. Unfortunately, 'duplicate' gives me the same error :\

As of 2023, duplicate track "X" to playlist "Y" only seems to fail if the track's underlying file can't be located. In that case, location of track "X" would return missing value.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.