0
votes

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).

It looks like this:

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. Is there a way I can get it to be recursive - I want to include files from the folders in the parent folder.

Thanks

Tardy

2

2 Answers

2
votes

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
1
votes

Solution #1: Using entire contents of the Finder - not very fast

set theFolder to "Macintosh HD:Temp to be Listened to:Temp on iPod:"
tell application "Finder" to set filesToAdd to files of entire contents of folder theFolder as alias list
tell application "iTunes" to add filesToAdd to user playlist "Temp on iPod"

Solution #2 : Using Spotlight - very fast, but the volume must be indexed.

set theFolder to "/Temp to be Listened to/Temp on iPod"
set fileList to paragraphs of (do shell script "mdfind -onlyin " & quoted form of theFolder & space & quoted form of "kMDItemContentTypeTree == '*public.audio*'")
set filesToAdd to {}
repeat with aFile in fileList
    set end of filesToAdd to POSIX file aFile as alias
end repeat
tell application "iTunes" to add filesToAdd to user playlist "Temp on iPod"