我正在寻找一个自动化工作流程,或者是一个可以使用名称列表(电子表格或.csv)来搜索目录及其子目录的自动化工作流程(但我还不熟悉该语言)特定文件名(具有不同的扩展名)并将该图像复制到为这些图像创建的文件夹中。
我发现一个脚本似乎与我需要的有些相似,但它不会在子目录中搜索,所以我还没有真正找到任何带有它的图像。
经过广泛的研究,我发现了两个看起来像我需要的不同脚本,但它们似乎都没有搜索子目录。以下是我尝试过的2个脚本。如果有人可以帮助我搜索子目录,我真的很感激!
脚本1:
set thePhotos to paragraphs of (read (choose file with prompt "Choose a text file"))
set theSourceFolder to (choose folder with prompt "Choose source folder")
set theDestination to (choose folder with prompt "Choose destination folder")
set dupeList to {}
repeat with theName in thePhotos
try
set end of dupeList to alias ((theSourceFolder as text) & theName)
end try
end repeat
tell application "Finder" to duplicate dupeList to theDestination with replacing
set theCount1 to (count of dupeList) as text
set theCount2 to (count of thePhotos) as text
display dialog (theCount1 & " of " & theCount2 & " items copied to " & (theDestination as text)) buttons {"OK"}
脚本2
set fileContents to read (choose file with prompt "Choose a comma-delimited text file")
set theText to result
set AppleScript's text item delimiters to ","
set theTextItems to text items of theText
set AppleScript's text item delimiters to {""}
theTextItems
set theSourceFolder to (choose folder with prompt "Choose source folder") as string
set theDestination to (choose folder with prompt "Choose destination folder")
repeat with theEPSName in theTextItems
tell application "Finder"
set theEPSFile to theSourceFolder & theEPSName
move file theEPSFile to folder theDestination with replacing
end tell
end repeat
因此,我可以选择要使用的.csv,选择要保存的目录并选择要搜索的目录。如何让这个脚本在子目录中搜索?对于了解Applescript的人来说,这看起来是否会根据需要发挥作用?
提前谢谢!我真的很感激这方面的任何帮助,因为这是我的第一次Applescript体验,但我很高兴能够学到它!
答案 0 :(得分:0)
使用shell和Spotlight搜索这是一个非常快速的解决方案。
该脚本创建搜索条件字符串
'kMDItemFSName == picture1.png || kMDItemFSName == picture2.jpg || ...'
然后执行搜索并通过将找到的项目传递给cp
命令来复制所有文件。
如果名单太长并且超过了shell参数的最大长度,可能会有一个警告。
set theNames to paragraphs of (read (choose file with prompt "Choose a text file" of type "txt"))
set sourceFolder to quoted form of POSIX path of (choose folder with prompt "Choose source folder")
set destinationFolder to quoted form of POSIX path of (choose folder with prompt "Choose destination folder")
set nameList to {}
repeat with aName in theNames
set end of nameList to "kMDItemFSName == " & quoted form of aName
end repeat
set {TID, text item delimiters} to {text item delimiters, " || "}
set nameFilter to quoted form of (nameList as text)
set text item delimiters to TID
do shell script "mdfind -onlyin " & sourceFolder & " -0 " & nameFilter & " | xargs -0 -J {} cp {} " & destinationFolder