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

时间:2016-05-31 10:53:39

标签: applescript itunes

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

看起来像这样:

  

告诉应用程序" iTunes"将theFolder设置为(" Macintosh HD:Temp为   收听:iPod上的Temp:")将with_subfolders设置为true --list   子文件夹与否(递归)将parent_folder设置为文件夹结束告诉

     

告诉应用程序"系统事件"将item_list设置为parent_folder结束   告诉

     

告诉应用程序" iTunes"将parent_folder的内容添加到用户   播放列表" Temp on iPod"结束告诉

但是,它只会从顶层/父文件夹导入iTunes中的文件。有没有办法可以让它递归 - 我想在父文件夹中包含文件夹中的文件。

由于

塔迪

2 个答案:

答案 0 :(得分:2)

您不需要从文件夹中获取所有文件,因为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 :(得分:1)

解决方案#1:使用Finder的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:使用Spotlight - 非常快,但必须将卷编入索引。

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"