【问题标题】:Applescript file search using data from a spreadsheet使用电子表格中的数据进行 Applescript 文件搜索
【发布时间】:2013-03-07 17:18:44
【问题描述】:

我目前正在使用这个 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

【问题讨论】:

  • excel 电子表格或 csv 将包含什么文件名?

标签: search csv applescript filenames


【解决方案1】:

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

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

亲切的问候,

标记

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    • 2020-06-07
    相关资源
    最近更新 更多