使用 Applescript 将特定文件夹的内容导入 iTunes
Import contents of specific folder into iTunes using Applescript
我创建了一个 Applescript,只需单击一下,即可将我硬盘上特定文件夹的内容添加到 iTunes(我真的想避免使用 iTunes 组织系统)。
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
但是,它只会将顶级 level/parent 文件夹中的文件导入 iTunes。
我想包含父文件夹中文件夹中的文件。
有什么方法可以使它递归吗?
解决方案 #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"
您不需要从文件夹中获取所有文件,因为 iTunes
从文件夹中自动递归执行此操作。
只需添加 parent 文件夹,如下所示:
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
我创建了一个 Applescript,只需单击一下,即可将我硬盘上特定文件夹的内容添加到 iTunes(我真的想避免使用 iTunes 组织系统)。
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
但是,它只会将顶级 level/parent 文件夹中的文件导入 iTunes。 我想包含父文件夹中文件夹中的文件。
有什么方法可以使它递归吗?
解决方案 #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"
您不需要从文件夹中获取所有文件,因为 iTunes
从文件夹中自动递归执行此操作。
只需添加 parent 文件夹,如下所示:
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