Search code examples
applescriptitunes

Import contents of specific folder into iTunes using Applescript


I have created an Applescript that will, with one click, add the contents of a specific folder on my hard drive to iTunes (I really want to avoid using the iTunes organisational system).

Applescript

tell application "iTunes"
  set theFolder to ("Macintosh HD:Temp to be Listened to:Temp on iPod:")
  set with_subfolders to true --list subfolders or not (recursion)   
  set parent_folder to theFolder
end tell

tell application "System Events"
  set item_list to parent_folder
end tell

tell application "iTunes"
  add contents of parent_folder to user playlist "Temp on iPod"
end tell

However, it only imports into iTunes the files from the top level/parent folder. I want to include files from the folders in the parent folder.

Is there a way I can get it to be recursive?


Solution

  • You do not need to get all files from a folder, since iTunes does this automatically and recursively from a folder.

    Just add the parent folder, like this:

    set parent_folder to "Macintosh HD:Temp to be Listened to:Temp on iPod:" as alias
    tell application "iTunes"
        add parent_folder to user playlist "Temp on iPod"
    end tell