1. Home
  2. Mac OS X
  3. Find delete files older than x days on macos

How to find and delete files older than X days on macOS

Files in the Downloads folder tend to build up over time. The same can be said for various other locations e.g., where you save screenshots to. If you can’t be bothered manually cleaning old files, you can use Automator to find and delete files older than X days on macOS.

Delete files older than X days

We’re going to use an Automator workflow to find and delete older files. The workflow can be set to run automatically everyday however, you will need to select all the files that need their lifespan checked. The workflow can be applied to a specific type of files e.g., images or documents, and it can be applied to specific file formats e.g., PNGs or JPEGs.

Open Automator and click New Document. Create a new Folder Actions document type.

We’re going to be adding several actions from the library to this workflow. The first action you want to add is the Ask for Finder Items action. Drag & drop it on to the right pane. Open the ‘Start at’ dropdown and select the folder you want to run the workflow on. You should also enable the ‘Allow Multiple Selection’ option.

Next, look for the ‘Set Value of Variable’ action in the library and add it to the right pane. You can change its name to something that tells you what it’s for.

It’s time to add a third action. Look for an action called ‘Filter Finder Items’ and add it to the right pane. This is where you will set the delete criteria for the files that you want to delete. I set this up so that it would delete images that are ten days old from a folder.

To that end, set the Condition to ‘All’ of the following are true. Open the dropdown next to ‘Kind’ and select the kind of files you want to delete e.g. Images. Next, click the plus button to add a second condition. This time, select Date Created. You can also select date modified or some other type of date.

This workflow will delete files that were created over ten days ago so select ‘Is not in the last’, ’10’, and ‘Days’.

The last action to add is ‘Move Finder items to trash’. Save the workflow and run it. It will delete all files that were created ten days ago. When you run it, you will see Finder open to the folder that the workflow is set to run on. Use the Command+A keyboard shortcut to select all the files and let the workflow do the rest.

To run it automatically, create an event in Calendar and set it as the trigger.

1 Comment