【发布时间】:2021-11-09 12:59:48
【问题描述】:
与here 描述的问题类似,我有一个带有文件名的文本文件,以及一个包含需要复制到另一个目的地的图像文件的文件夹。由于这些文件经常有数百个,因此自动执行此任务会很有帮助。
挑战在于文本文件中的某些文件可能不存在,而我拥有的当前版本的脚本无法解决这种情况并引发错误。
总之,我想使用 Automator & Apple Script 来:
- 请求包含原始文件的源文件夹
- 询问应将它们复制到的目标文件夹
- 请求一个带有文件名的文本文件
- 从文本文件中读取名称
- [new] 检查是否存在匹配文件并将其复制到目标位置
- [new] 如果没有匹配的文件,则跳过该行并继续下一行
这是我目前所拥有的——只要文本文件中的每一行都有一个实际的图像,它就可以工作:
还有 AppleScript:
on run {input, parameters}
set imgDestination to input's item 2
set imgSource to input's item 1
set imgNameFile to choose file with prompt {"Select file of image filenames:"}
set imageList to every paragraph of (read imgNameFile)
repeat with eachName in imageList
tell application "Finder"
set targetImageFile to item 1 of (get every file in folder imgSource whose name = (eachName as text))
duplicate targetImageFile to folder imgDestination
end tell
end repeat
return input
end run
不幸的是,我的技能不足以为 5 和 6 提出 if/else 方案,因此我们将不胜感激。
【问题讨论】:
标签: macos automation applescript automator finder