使用电子表格中的数据搜索Applescript文件



我目前正在使用这个Applescript,我发现搜索文件名并返回文本文档中的文件路径。这对于查找1或2个文件很有效,但我想查找分布在数百个文件夹中的500个文件。我理想的脚本将使用excel电子表格或csv中的数据,执行搜索,找到文件并将其复制到桌面上指定的文件夹中。如有任何帮助,不胜感激。

下面是我找到的脚本:

tell application "System Events"
    activate
    set thePattern to text returned of (display dialog "Search for" default answer "")
    end tell
    if thePattern = "" then return
   try
    set foundFiles to do shell script "mdfind -name " & quoted form of thePattern & " |         /usr/bin/egrep -i " & quoted form of thePattern & "[^/]*/?$ | /usr/bin/grep -vi " & quoted     form of thePattern & ".*" & quoted form of thePattern
on error
    set foundFiles to "Nothing Returned"
end try
if foundFiles = "" then set foundFiles to "Nothing Returned"
tell application "TextEdit"    
activate
delay 0.5
try
    set theDoc to document 1
    get text of theDoc
    if result is not "" then
        make new document
        set theDoc to result
    end if
on error
    make new document
    set theDoc to result
end try
set text of theDoc to foundFiles
end tell

需要从文本文件中读取数据,然后将其转换为以回车或换行分隔的列表,并对该列表中的项执行重复操作。然后将每个项目(实际上是一行)转换为例如制表符分隔的列表,并再次对该列表中的项目进行(嵌套)重复循环。如果你知道item3是文件路径,你可以设置一个变量到该行的item3作为文本,并在shell脚本中使用这个变量。

我认为你需要通过发布自己的实现尝试来表明你理解重复循环的概念。如果你愿意,我很乐意回来帮助你进行下一步。

亲切的问候,马克

最新更新