Scripting iTunes Folder Playlists

Discussion in 'Mac Programming' started by jabrowntx, Jan 12, 2011.

  1. jabrowntx macrumors 6502

    Joined:
    Jul 5, 2007
    #1
    I'm trying to script the creation of folders and subfolders in iTunes so that I get:

    Albums
    -- Pop
    -- Rock
    -- etc...

    But, I'm hung-up on what should be a simple if not exists statement which, for some reason, is always coming back as "false" and creating a subfolder with the same name.

    The code below is just a sample bit I'm using to try to get this working. Eventually (if I can ever get this working) is to loop through all the album titles in my library create a folder for each genre under the main Album folder, then create a playlist for the album in the appropriate genre.

    Code:
    tell application "iTunes"
    	if not (exists folder playlist "Albums") then
    		make folder playlist with properties {name:"Albums"}
    	end if
    	
    	if not (exists folder playlist "Rock" of folder playlist "Albums") then
    		make new folder playlist at folder playlist "Albums" with properties {name:"Rock"}
    	end if
    end tell
    
    The first if not block works correctly when I run the script multiple times, but the second block which creates the subfolder always creates a new instance with the same name (ie, if I run the script 3 times, I get 3 folders named Rock under Albums).

    I've also tried
    Code:
    if (exists folder playlist "Rock" of folder playlist "Albums") is false then
    		make new folder playlist at folder playlist "Albums" with properties {name:"Rock"}
    
    Any ideas as to what I'm doing wrong?
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    Not particularly, but I'd like to understand the "why". Can't you just use the iTunes browser or create smart playlists within iTunes?

    Is there a reason you need to change the way iTunes stores its files in the file system that wouldn't best be handled using the database within iTunes?

    B
     
  3. jabrowntx thread starter macrumors 6502

    Joined:
    Jul 5, 2007
    #3
    Using iTunes browser is fine, but I'm (trying to) do this for a few reasons:

    1) Learning Applescript
    2) I have over 400 albums, creating smart playists takes a long time.
    3) If I were to lose or accidentally delete some or all of the playlists, I can just re-run the script, and viola' - done!

    The reasons I'd like genres as subfolders is so if I'm in the mood for a certain type of music, but not really sure who/what, I can browse that way.
     
  4. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #4
    You could use Applescript to create the smart playlists based on the Genres you have. :p

    Here's why I just don't recommend this. My library is huge, built on 800+ physical CDs and counting, plus lots of stuff bought from iTunes, Amazon etc... and even though I have spent a lot of time getting everything tagged properly it's still not perfect.

    For example I have these variations of genres in my current library.

    • Dance, Dance & DJ, Electronica/Dance
    • Alternative, Alternative Rock, Alternative & Punk, Alternativo, Alternativo & Rock Latino
    • Latin, Latino, Alternativo & Rock Latino, Rock Latino, Contemporary Latin, Pop Latino, iTunes Latino, Latin Jazz, Latin Music
    • Jazz, Latin Jazz, Fusion
    • Pop, Pop/Rock, Pop Latino

    I can't combine them programmatically into subfolders, but I can do so easily as smart playlists.

    http://smartplaylists.com/

    B
     
  5. jabrowntx thread starter macrumors 6502

    Joined:
    Jul 5, 2007
    #5
    For genres, I do create smart playlists.

    For albums, however, I only want playlists for the complete albums that I have (for that I have prefixed the album name a certain way so I know which ones they are -- which also makes it easier for me to create static playlists programmatically). I have also gotten rid of all of the sub-genres as much as possible.

    Everybody has their own methods for managing their music library - I'm trying to automate mine a bit so I don't have to spend a lot of time doing it.

    The way I had planned doing the folder structure is to create "Albums" folder and as part of the loop structure, I was going to get the genre for each album and create the folder that way. I just can't get past how/why Applescript is not handling the sub-folder creation as expected.
     
  6. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #6
    Fully understood, and it sounds like you have a good method in mind.

    My only quibble is the use of the file system and folders outside iTunes instead of self-updating smart playlists within iTunes. This seems to go against the grain of the design of iTunes with its default settings and seems like it would end up violating your second goal (spending a lot of time doing it).

    Playlist folders really sealed the deal for me as I have my library sliced and diced by many criteria, all fully automatically.

    I use a normal "dumb" playlist to separate albums from singles (singles are added manually to the "Singles" playlist) and then I can use that playlist as a criterion in other smart playlists.

    B
     

Share This Page