下面是一个使用AppleScript在多个文件夹中查找最接近给定时间的文件的示例代码:
set targetTime to current date -- 设置目标时间
set folderPaths to {"/path/to/folder1", "/path/to/folder2", "/path/to/folder3"} -- 文件夹路径列表
set closestFile to missing value
set closestTimeDiff to missing value
repeat with folderPath in folderPaths
tell application "Finder"
set folderRef to folder folderPath
set allFiles to every file of folderRef
repeat with fileRef in allFiles
set fileDate to modification date of fileRef
set timeDiff to targetTime - fileDate
if closestTimeDiff is missing value or timeDiff < closestTimeDiff then
set closestFile to fileRef
set closestTimeDiff to timeDiff
end if
end repeat
end tell
end repeat
if closestFile is not missing value then
display dialog "最接近目标时间的文件是:" & name of closestFile
else
display dialog "未找到满足条件的文件"
end if
要使用此代码,您需要将/path/to/folder1
,/path/to/folder2
等替换为实际的文件夹路径列表。然后,将targetTime
设置为您希望查找最接近的时间。运行脚本后,将显示最接近目标时间的文件的名称。如果没有找到满足条件的文件,将显示相应的消息。