Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Get the last playlist of a folder in iTunes

Hi,


I'd like to get the last playlist of a folder playlist in iTunes and integrate it with Automator.


I'm a very beginner in AppleScript but familiar with OOP (ex AS3 dev) so I looked for the doc in script editor where I can see :

folder playlistn [inh. user playlist > playlist > item] : a folder that contains other playlists

So, if I understand well, a folder playlist is an item and I have to get the item 1 of the folder playlist to work with it but after that I don't know what to do.


Here is my script :

on run {input, parameters}
  set folder_p to input

  tell application "iTunes"
  set itm to ((item 1) of folder_p)
  end tell

  return itm
end run


But itm is exactly the same than folder_p and I don't know how to get the last playlist.


Any idea ? Thx a lot.

Posted on Apr 25, 2015 12:36 PM

Reply
4 replies

Apr 26, 2015 12:15 AM in response to Combo

I think you're misinterpreting the inheritance model here. At its lowest level, pretty much everything is an item, but that just gives objects a common framework for giving them names, IDs, classes, etc. You rarely (if ever) directly interact with the item class itself.


In the case of folder playlists, it's not clear to me a) what it is you're trying to do, or b) how you're invoking this (and, by extension, what the input to your Automator action is. However, if I look directly at your question:


I'd like to get the last playlist of a folder playlist in iTunes


That's pretty trivial:


tell application "iTunes"

get last folder playlist

end tell

(but bear in mind, the actual definition of 'last' is undefined here - it could be the 'last created', or 'last by alphabetical order', or even 'last played'.)


I suspect there's more to your goal here, though, so what is your actual plan here?

Apr 27, 2015 6:48 AM in response to Combo

Hi,


To get the last user playlist from a folder :

on run {input, parameters}
    tell application "iTunes"
        set folder_p to item 1 of input
        set userPlaylists to user playlists
        set tc to count userPlaylists
        repeat with i from tc to 1 by -1
            set p to item i of userPlaylists
            try
                if (parent of p) = folder_p then return p -- the last user playlists at root of folder_p
            end try
        end repeat
    end tell
end run



To get the first user playlist from a folder :

on run {input, parameters}
    tell application "iTunes"
        set folder_p to item 1 of input
        set userPlaylists to user playlists
        repeat with p in userPlaylists
            try
                if (parent of p) = folder_p then return contents of p -- the first user playlists at root of folder_p
            end try
        end repeat
    end tell
end run




If this folder playlist contains other folders, and you want to get a playlist in a subfolder, this requires another script.

May 4, 2015 10:33 AM in response to Combo

Hi,


Combo wrote:


Thx a lot, it works !


But is it mandatory to do a loop in all the user playlists ?





Yes, the loop is needed.


The AppleScript action get the output of "Obtenir les éléments iTunes indiqués" action"

The output is in the input variable, this variable is always a list.

folder_p is the first and unique element in the input variable --> the folder playlist "Juke Box"

To get an user playlist in the the folder playlist "Juke Box", the script need to check the parent in all the user playlists

Because these syntaxes are not working :

return playlists of folder_p -- this return a empty list
return user playlists of folder_p -- this return a empty list
return folder playlists of folder_p -- this return a empty list


You can use a filter like this :

return playlists whose name contains "CD " -- this work
return user playlists whose smart is true -- get smart playlists, this work


But it doesn't work with the parent property

return playlists whose parent is folder_p -- error

Get the last playlist of a folder in iTunes

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.