Quick and dirty answer : study the command “with timeout” described in AppleScript Language Guide
As far as I remember when we don’t use with timeout, the default limit is set to 60 seconds.
Try to use with timeout of 120 seconds.
Here the job is done in 41,482059001923 seconds on a folder containing 430 files.
Alternate answer :
Several authors posted more efficient code using ASObjC because Finder is a slow beast.
Here is an edited version of such a proposal.
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone { Heavy Lifting by Shane Stanley }
# dCre: 2016/05/13 23:06
# dMod: 2016/05/16 07:51
# Appl: AppleScriptObjC
# Task: listFilesByExtension → Handler → Example Sweeper
# Aojc: True
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @List, @Files, @Extension, @File_Extension, @Sweeper
-------------------------------------------------------------------------------------------
use framework "Foundation"
use scripting additions
-------------------------------------------------------------------------------------------
set sourceFolder to POSIX path of (path to downloads folder from user domain)
(*
set applescriptFileList to its listFilesByExtension:{"scpt", "scptd", "applescript"} fromDirectory:sourceFolder
set bbeditWorksheetList to its listFilesByExtension:{"worksheet"} fromDirectory:sourceFolder
set clippingFileList to its listFilesByExtension:{"textClipping"} fromDirectory:sourceFolder
set compressedArchiveList to its listFilesByExtension:{"sit", "zip"} fromDirectory:sourceFolder
set diskImageList to its listFilesByExtension:{"dmg"} fromDirectory:sourceFolder
set imageFileList to its listFilesByExtension:({"gif", "jpg", "png"} & {"jpeg", "tif", "tiff "}) fromDirectory:sourceFolder
set movieFileList to its listFilesByExtension:{"flv", "mov", "mp4"} fromDirectory:sourceFolder
*)
set pdfFiles to its listFilesByExtension:{"pdf"} fromDirectory:sourceFolder
(*
set rtfFileList to its listFilesByExtension:{"rtf", "rtfd"} fromDirectory:sourceFolder
set textFileList to its listFilesByExtension:{"txt"} fromDirectory:sourceFolder
set webArchiveList to its listFilesByExtension:{"webarchive"} fromDirectory:sourceFolder
set webBookmarkList to its listFilesByExtension:{"webbookmark", "webloc"} fromDirectory:sourceFolder
{applescriptFileList, bbeditWorksheetList, clippingFileList, compressedArchiveList, diskImageList, imageFileList, movieFileList, pdfFiles, rtfFileList, textFileList, webArchiveList, webBookmarkList}
*)
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on listFilesByExtension:listOfExtensions fromDirectory:sourceFolder
set fileManager to current application's NSFileManager's defaultManager()
set aURL to current application's |NSURL|'s fileURLWithPath:sourceFolder
set directoryContents to fileManager's contentsOfDirectoryAtURL:aURL includingPropertiesForKeys:{} options:0 |error|:(missing value)
set foundItemList to current application's NSPredicate's predicateWithFormat_("pathExtension.lowercaseString IN %@", listOfExtensions)
set foundItemList to directoryContents's filteredArrayUsingPredicate:foundItemList
# Return as a list of «class furl»'s
return foundItemList as list
# Return as a list of POSIX Paths
# set foundItemList to (foundItemList's valueForKey:"path") as list
# return foundItemList
end listFilesByExtension:fromDirectory:
-------------------------------------------------------------------------------------------
Here, that took 0,005519986153 seconds.
Yvan KOENIG running High Sierra 10.13.4 in French (VALLAURIS, France) vendredi 6 avril 2018 18:23:08