Check if file is older than X days

Today I needed a rule in hazel which was able to check if a file was older than X days.

While there are some options in hazel like before this year, I mistrusted them to work in
the correct way and I wanted to do some more applescript.
So I wrote a quick applescript to check if the file modified date is older than X days and than
return a true.


-- Set the age of files that you want to keep
set keepDays to (360)
tell application “Finder”
set modDate to modification date of theFile
if modDate is less than ((current date)) - keepDays * days then
return true
end if
end tell
— File is younger than keepDays
return false

Advertisements

One thought on “Check if file is older than X days

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s