property modDate : ""
activate
deletIt(choose folder multiple selections allowed yes)
on open (var)
deletIt(var)
end open
on deletIt(var)
set posPath to POSIX path of item 1 of var
repeat
try
set modDate to text returned of (display dialog "Delete older then how many days?" default answer modDate with title posPath with icon 1) as number
if modDate < 1 then error
exit repeat
on error number ernmb
if ernmb = -128 then error number -128
display alert "Value has to be a number greater then 0" as critical
end try
end repeat
set {dateVar, endlist, amount} to {current date, "", 45}
repeat with x in var
tell application "Finder"
try
set {fiList, pathName} to {(name of files of entire contents of folder x whose modification date is less than dateVar - modDate * days), name of container of x}
on error erstrg number ernmb
display alert erstrg message ernmb as critical
return
end try
end tell
end repeat
repeat with y in fiList
if (count paragraphs of endlist) ≤ amount then
set endlist to endlist & " " & y & return
else
set endlist to endlist & " and " & (count item of fiList) - amount & " more...‼️"
exit repeat
end if
end repeat
display alert "Move files in " & quoted form of pathName & " to the trash?" message endlist buttons {"Cancel", "Trash"} cancel button "Cancel" default button "Trash" as critical
repeat with x in var
tell application "Finder"
try
delete (files of entire contents of folder x whose modification date is less than dateVar - modDate * days)
on error number ernmb
display alert ernmb as critical
end try
end tell
end repeat
end deletIt