使用Applescript将特定文件夹的内容导入iTunes



我创建了一个Applescript,只需单击一下,就可以将硬盘驱动器上特定文件夹的内容添加到iTunes中(我真的很想避免使用iTunes组织系统)。

苹果脚本

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

但是,它仅将顶级/父文件夹中的文件导入iTunes。我想在父文件夹中包含文件夹中的文件。

有没有办法让它递归?

您不需要从文件夹中获取所有文件,因为iTunes从文件夹中自动递归地执行此操作。

只需添加文件夹,如下所示:

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:使用entire contents查找器 - 不是很快

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"

解决方案#2:使用聚光灯 - 非常快,但必须对音量进行索引。

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"

最新更新