Automater - Move Files Older Than 1 Week To Trash

I am trying to create a folder action that moves to the trash all my screenshots that are older than 1 week from my screenshot folder to the trash. In doing this it seems to immediately deletes new screenshots but the ones in the folder that are from yesterday to 1 week ago aren’t deleted. Can someone tell me why this would happen or what I did wrong?

It is puzzling and I do not see that you did anything wrong. Somehow the phrase is not in the last 1 weeks applies to files that were created earlier than a week ago (of course) AND to files that were created today (what??). That is not logical to most of us.
I would consider this a bug. But it has been around for a long time. And in Automator, for your purposes, I cannot see an easy workaround.

Hazel, of course, is designed for such a purpose and would easily be set up to do what you want if you own that app.

If my Mac was a work machine I would purchase but as something I use as a more of a hobby I don’t feel like spending the $30 for it currently.

Check out this link.

http://www.nickshubin.com/articles/mac/find_finder_item.html

Chances could be that a Spotlight timing issue is the root cause here. As it suggests, perhaps try redesigning the Automator action to Filter Finder Actions and see if that addresses the issue.

Not to say that BBech should not try this, but for me this approach does not work. On my machine, Spotlight correctly identified the files as having been created today and yet Automator considers them not to have been created in the last 1 weeks.

Filter Finder Actions did not change the behavior.

1 Like

This is still an issue, at least in High Sierra. Hard to believe something so simple on the surface should malfunction so fundamentally

Two things:

First, I got it to correctly move files by “Date created”—explained below—but it only seems to be able to work with files as they enter into the folder. For example, if an older file is manually dropped into the folder, it gets moved, as per the rules. But, older files that were already in the folder are not “looked” at and so remain untouched. So, newly created files that are placed in the folder remain in the folder, as per the rules, but older files that were put in the folder in the past are not “looked” at by the Folder Action, and so they too remain in the folder.

Question: When creating a Folder Action is there a way to have all the files be looked at inside a folder, and not just the files that are newly added? [Edit: I found a solution, see reply further down.]

Second, to move files by “Date Created” select “None of the following are true.” Whereas, using “Any of the following are true” does not work (—can’t think of why, must be a bug). Then combine this with “Date Created is in the last”—instead of “Date Created is not in the last”. I also had to add “Date created is Today,” to get files created “Today” to be ignored.

But, again, only useful if manually dropping files into the folder. [Edit: Solution found, see below]

Maybe a script can make it work on files already in the folder. Or perhaps instead of using a Folder Action, perhaps it can be done with a Calendar Alarm (one of the workflow types when first setting up an Automator workflow).

I don’t think so. I believe it is event driven so there’s no event that occurs for existing files. Just move them out and back in.

Yes, but that’s a one shot as from then on you are only processing new files. Building a solution based on batch processing would be useful if you would change which folders something is run on and if it were scheduled or run manually rather than through a folder action.

Better in my opinion to move the files out, then back in and use process on a queued, per item basis in the background. Closer to real time processing and lower overall overhead (though overheads are likely minimal for anything but really large data volumes).

Got it working. The following makes Automator look at pre-existing files—files already in the folder, and not only the files just placed into the folder—and trashes the files older than a specified age.

[Obscure behavior not likely to be encountered with the intended use: if you drag files from the Trash to the Screenshots folder (or whichever folder that is attached to this Folder Action) then the expected behavior fails.]

How it was done:

  1. Folder Action — choose folder you want to use – example: “Screenshots”
  2. Get Specified Finder Items — Add… “Screenshots”-- this is the same folder as step 1
  3. Get Folder Contents
  4. Filter Finder Items
    None of the following are true
    • Date created is today
    • Date created is in the last X weeks (or days, or months)
  5. Move Finder Items to Trash

(An alternative to step five if not wanting to trash them: Move Finder Items, To: another folder)

macOS 10.15.7 Catalina
Automator 2.10