0

I try to write an Applescript that would sort playlists by album. That is, a playlist P might contain 20 tracks split on 4 albums (A1, A2…). Each album has 10 tracks, in other words, on this playlist, the albums on average only contain half of the tracks.

I have found a lot of examples where you can query iTunes for all tracks that belong to an album on the library level, typically something like this

set albumSongs to (every track of library playlist 1 whose album is currentAlbum)

while I want to do something like this

set albumSongs to (every track of playlist myPlaylist whose album is currentAlbum)

but compiling my example returns an error message Expected class name but found identifier. pointing at the track keyword in the line above.

Update:

The unfinished function I try to write where I want to get all tracks that belong to a certain album

on sortPlaylist(albumList, currentPlaylist)
    repeat with currentAlbum in albumList
        set albumSongs to (every track of currentPlaylist whose album is currentAlbum)
    end repeat
end sortPlaylist

It takes a list without duplicates of all albums (albumList) and the playlist (currentPlaylist) I want to work with. I still have no code to actually sort it (input is appreciated!) but the plan is to sort albumSongs in track order and then add the tracks to the playlist in order.

1

Try:

set playlistName to "playlist name"

tell application "iTunes"
    set playlistReference to first playlist whose name = playlistName
    set currentAlbum to album of current track
    set albumSongs to (every track of playlistReference whose album is currentAlbum)
end tell
  • Still the same error message. – d-b Nov 30 '14 at 9:56
  • Have you tried making a new script and pasting only my code into it? – adayzdone Nov 30 '14 at 13:46
  • I just did and then it works. Surprising. I don't understand what significant difference there is between yours and mine code. – d-b Nov 30 '14 at 15:44
  • You never included a tell application "iTunes" block in your handler – adayzdone Nov 30 '14 at 16:48
  • But I have a tell application itunes in the function calling this subroutine. Something like tell applictation "itunes" sortPlaylist (arg1, arg2) end tell sortPlaylist (arg1, arg2) [your code here] end Doesn't this function inherit the tell itunes? – d-b Dec 1 '14 at 6:49
0
set albumSongs to (every track of playlist (name of myPlaylist) whose album is currentAlbum)
  • Still the same error message. – d-b Nov 30 '14 at 9:55
  • could you post more of your code ? It would be easier to help you... – Maxwell77 Nov 30 '14 at 15:23
  • More code added. – d-b Nov 30 '14 at 15:42
  • 1
    @adayzdone have found the solution, your handler should be in a tell application "iTunes" block. – Maxwell77 Nov 30 '14 at 17:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .