iTunes - problem creating subfolders in playlist folders

Hi,

This is probably a simple question, but having searched the web, I can’t find an obvious answer.

I know that I can create playlist folders in iTunes, and move the folders with code such as:

But, how do I:

A) move another folder, e.g. test3, into the test2 folder? I.E. how do I move folders to subfolders?

B) even better, how can I directly create folder “test3” inside of folder “test2”, instead of creating then moving it?

Hi,

just specify the insertion location


tell application "iTunes"
	set testFolderPlayList to make folder playlist with properties {name:"test"}
	make folder playlist at testFolderPlayList with properties {name:"test2"}
end tell

Hi,

many thanks for this, but unless I am missing something, I still don’t understand how you insert a subfolder into an existing subfolder.

I.E.

Test
-----------> Test2
----------------------> Test3

How do I specify the insertion point for folder Test3?

Although the folder playlists seem nested, they are all on the same playlist level


tell application "iTunes"
	set test2FolderPlayList to folder playlist "test2"
	make folder playlist at test2FolderPlayList with properties {name:"test3"}
end tell

Thanks for the quick reply. If all folder playlists are at the same playlist level, then this complicates what I am trying to achieve.

For example, if I had the following, which iTunes allows you to do, then how do I know which “70s Albums” playlist folder I would be referring to in order to insert another subfolder.

Aerosmith
----------------------> 70s Albums
Whitesnake
---------------------> 70s Albums

Confusingly, iTumes even seems to allow identically named playlist folders at the same level. So, is there another method of referring to them? “PresistentID” seems to ring a bell, but I can’t remember where I saw that - possibly in another Applescript I was looking at on Doug’s scripts for iTumes website.

folder playlists have a parent property which contains the parent element.
Unfortunately it cannot be determined with the whose filter, so use a repeat loop


set aeroSmithPlaylist to missing value
tell application "iTunes"
	set Albums70sFolders to folder playlists whose name is "70s Albums"
	repeat with oneFolder in Albums70sFolders
		if parent of oneFolder is folder playlist "AeroSmith" then
			set aeroSmithPlaylist to contents of oneFolder
			exit repeat
		end if
	end repeat
	if aeroSmithPlaylist is not missing value then
		make folder playlist at aeroSmithPlaylist with properties {name:"1975"}
	end if
end tell

Thanks once again. Thinking about this, I might have been over complicating things.

I have a script that makes a playlist for each album in my library, creates a playlist folder named after the album, and then moves the playlist to the playlist folder . These are all stored in a “Albums” playlist folder

I also have another script that makes a playlist folder for each artist in the library, which are stored in a “Artists” playlist folder.

What I would like to do is move each album playlist folder to reside in the Artists folder, underneath the relevant Artist playlist folder. Is there a simple way to achieve this? Something like:

“Set targetartist to artist of track 1 of playlist PlRef”
“Move parent folder of playlist PlRef to playlist folder targetartist”

I.E.

Albums
--------------------> Pump (with playlist of Pump contained within)

Artists
--------------------> Aerosmith
--------------------------------------> Move the “Pump” playlist folder and the playlist it contains to here

Thanks for the help so far. I don’t have much AppleScript experience and your examples help immensely.

Got this working now. It is the Persistent ID that is the key to use, i.e.



tell application "iTunes"
	
	set targetartist to (the artist of track 1 of playlist "Get A Grip")
	
	set sourceplfolder to persistent ID of (some folder playlist whose name is "Get A Grip")
	
	set destplfolder to persistent ID of (some folder playlist whose name is targetartist)
	
	move (some folder playlist whose persistent ID is sourceplfolder) to (some folder playlist whose persistent ID is destplfolder)
	
end tell



I’ve hit another dead end :frowning:

I’m trying to move some already created (but empty) playlist folders named the same as an existing playlist (i.e. playlist of “2X again” and a empty playlist folder of "2X again) to sit under a playlist folder named after the artist of track 1 of the playlist, and then the move the playlist itself to the empty playlist folder)

I.E.

Playlist of “Appetite for Destruction” (artist of track 1 is “Guns n’ Roses”)
Move empty playlist folder of “Appetite for Destruction” to playlist folder named “Guns n’ Roses”.
Move “Appetite for Destruction” playlist to playlist folder named “Appetite for Destruction”

This is the code I am trying:


tell application "iTunes"
	
	
	set excludedplaylists to {"Library", "Music", "Movies", "TV Shows", "Podcasts", "Books", "Purchased", "iTunes DJ", "Top 25 Most Played", "80's Cheese"}
	
	set PlayListComplete to name of every playlist
	
	repeat with thePlaylist in PlayListComplete
		
		set prohibited to false
		
		if thePlaylist is in excludedplaylists then
			set prohibited to true
		end if
		
		
		if not prohibited then
			set sourcealbumpl to persistent ID of (some playlist whose name is thePlaylist)
			
			set targetalbumfolder to the album of track 1 of (some playlist whose persistent ID is sourcealbumpl)
			
			set targetartist to the artist of track 1 of (some playlist whose persistent ID is sourcealbumpl)
			
			set destalbumplfolder to persistent ID of (some folder playlist whose name is targetalbumfolder)
			
			set destartistplfolder to persistent ID of (some folder playlist whose name is targetartist)
			
			move (some folder playlist whose persistent ID is destalbumplfolder) to (some folder playlist whose persistent ID is destartistplfolder)
			
			move (some playlist whose persistent ID is sourcealbumpl) to (some folder playlist whose persistent ID is destalbumplfolder)
		end if
		
		
	end repeat
	
	
end tell

But I get the following:

error “iTunes got an error: Can’t get album of track 1 of some playlist whose persistent ID = "17D0AB8AE89C947E".” number -1728 from album of track 1 of some playlist whose persistent ID = “17D0AB8AE89C947E”

All help appreciated!

This is driving me nuts because it’s so inconsistent. Sometimes the code I posted previously works for a few playlists then gives the error again, i.e.

Sigh. As usual with Applescript, a seemingly trivial task is actually complicated, at least according to (the admittedly old) posts on http://forums.ilounge.com/applescripts-itunes-mac/168400-using-itunes-persistent-id.html

Any ideas on a different way to approach this? Maybe parse the XML library file?