(* Original https://discussions.apple.com/thread/7230461 *) use AppleScript version "2.4" -- requires Mac OS X 10.11 (Yosemite) use scripting additions use framework "Foundation" my deleteOlderItems(POSIX path of (path to downloads folder)) on deleteOlderItems(thisPath) set thisURL to current application's |NSURL|'s fileURLWithPath:thisPath set oldDate to current application's NSDate's dateWithTimeIntervalSinceNow:(-86400 * 7) -- get date of 7 day ago set theNSFileManager to current application's NSFileManager's defaultManager() set allNSURLs to (theNSFileManager's contentsOfDirectoryAtURL:thisURL includingPropertiesForKeys:{current application's NSURLAddedToDirectoryDateKey} ¬ options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(missing value)) set mylist to {} repeat with theUrl in allNSURLs -- get the date added set {theResult, theValue, theError} to (theUrl's getResourceValue:(reference) forKey:(current application's NSURLAddedToDirectoryDateKey) |error|:(reference)) -- compare the date if theResult and (theValue's compare:oldDate) = -1 then set end of mylist to theUrl as alias end repeat if mylist is not {} then tell application "Finder" to delete mylist display notification "Очистка каталога Downloads выполнена." & return & "Удалено объектов:" & space & (count of mylist) end if end deleteOlderItems