在AppleScript中,可以使用"do shell script"命令来执行shell命令,并将输出结果返回给AppleScript。因此,你可以使用命令行工具来找到指定文件夹中具有特定扩展名的文件。
以下是一个示例代码,演示如何使用AppleScript找到指定文件夹中扩展名为DWG或STEP的文件:
set folderPath to (choose folder) as text
set fileExtension to {"dwg", "step"}
set foundFiles to {}
-- 使用shell命令查找指定文件夹中的文件
repeat with ext in fileExtension
set shellCommand to "find " & quoted form of folderPath & " -name \"*." & ext & "\""
set shellResult to do shell script shellCommand
-- 解析shell命令的输出结果
set fileList to paragraphs of shellResult
-- 将找到的文件添加到结果列表中
repeat with file in fileList
set end of foundFiles to file as text
end repeat
end repeat
-- 打印找到的文件列表
repeat with file in foundFiles
log file
end repeat
在这个示例中,首先使用choose folder
命令让用户选择一个文件夹。然后,定义一个包含需要查找的文件扩展名的列表fileExtension
。
接下来,使用do shell script
命令和find
命令来在指定文件夹中查找具有指定扩展名的文件。find
命令的输出结果将通过do shell script
命令返回给AppleScript。
然后,将shell命令的输出结果解析为一个文件列表,并将找到的文件添加到foundFiles
列表中。
最后,使用log
命令打印找到的文件列表。你可以根据需要修改代码,以适应你的具体需求。