I am trying to create a small script that lets me empty the downloads folder of my account. A feature is that I want to be able to specify through a dialog box how many days back i want to keep files.
The script looks like this:
on run
repeat
set dialogResult to (display dialog "Tast inn antall dager du vil at skal bevares" default answer "1")
try
set antallDager to (text returned of dialogResult) as number
if (class of antallDager is integer) then exit repeat
(* if (startNumber = startNumber as integer) then
set startNumber to startNumber as integer
exit repeat
end if *)
end try
display dialog "The starting number needs to be a valid integer!" buttons {"Enter again", "Cancel"} default button 1
end repeat
tell application "Finder"
try
delete (every item of folder "Downloads" of folder "JSF" of folder "Users" of disk "OS X" whose modification date is less than (((get current date) - antallDager * days)))
end try
end tell
end run
Its my first script, so the code is probably far from “best practice”, but at the moment it does the trick except for 1 thing.
How can i get a hold of an items “Date Added” information? I see that you can sort your download folder by it, but in the Finder Dictionary in Apple Script Editor i can only find “modification date” and “creation date”.
Any inputs on this? THings to improve the script? How to change modification date to date added?
Kringon