iTunes: get every playlist not in a specific playlist folder

is this possible?

Im trying to repeat my script over each playlist that isn’t in a folder.

Hi,

reading the property parent throws an error if the playlist is not in a folder


tell application "iTunes"
	repeat with aPlaylist in (get user playlists of source "Library")
		try
			parent of aPlaylist
		on error
			-- do something with aPlaylist
		end try
	end repeat
end tell

Hi,

Not sure if you can use this, but you may be able to check for existence. Still checking it out and might need to do speed tests.

tell application "iTunes"
	if not (exists parent of playlist "Various1") then
		beep 2
	end if
end tell

Thanks, both these works, but how would I modify this to work with a specific folder, for instance.
I want my script to target all playlists not in a folder named “IGNORE”.

Or is it possible to ‘get every playlist in a playlist folder’? I have tried many way in my script to achieve this, and searched online, but no answers.

Hi fhill2,

After thinking about it, what I usually do when I want everything that is not something else, is make a smart playlist. You might want to look into that.

gl,
kel

Usually I would do that, but in this case I’m rebuilding my iTunes hierachy in the Finder and only want the script to be performed on certain playlists not within a folder. A smart playlist won’t help me.
and I’ve answered my own question here . I came up with this script which will test to see if a playlist belongs to a certain playlist folder.

Thanks for previous ‘parent’ advice which helped me solve this problem


tell application "iTunes"
	
	set thePlaylists to get every playlist whose special kind is none
	set theNewPlaylists to {}
	
	repeat with thePlaylist in thePlaylists
		set theTarget to thePlaylist
		
		repeat
			try
				set theTarget to parent of theTarget
			on error
				
				
				exit repeat
			end try
			
		end repeat

		if (name of theTarget) is not equal to "IGNORE" then set the end of theNewPlaylists to thePlaylist
		
		
	end repeat
	
end tell


I usually do that, but in this case I’m designing a script that imports my iTunes playlists into the Finder. But I only want it to run over playlists that are not in the “IGNORED” folder.

I have found this script, from this post.
http://stackoverflow.com/questions/15408694/how-do-i-select-playlists-in-a-subfolder-in-itunes-using-applescript

tell application "iTunes"
    set myList to {}
    set myFolder to folder playlist "testFolder"

    set myPlaylists to playlists
    repeat with aPlaylist in myPlaylists
        try
            if aPlaylist's parent = myFolder then set end of myList to aPlaylist's name
        end try
    end repeat

    return myList
end tell

This successfully gets the playlists in a folder, but doesn’t account for playlists of playlists folders in that folder. (uh confusing :o)

I’ve tried this. Which attempts to count up to the final parent. But doesn’t work :frowning:


tell application "iTunes"
	
	set thePlaylists to get every playlist whose special kind is none
	set theNewPlaylists to {}
	

	repeat with thePlaylist in thePlaylists
		set theTarget to thePlaylist
		
		repeat
			try
				set theTarget to parent of theTarget
			on error
				
				
				exit repeat
			end try
			
		end repeat
		if (name of theTarget) is not equal to "IGNORED" then set the end of theNewPlaylists to thePlaylist
		
		
	end repeat
	
end tell