On Friday, we showed you how to clear files out your Mac’s Downloads folder and back them up to another loacion. This time we’re going show you how to purge those Old Download archives on a monthly basis. This time we’re playing around with the Find command in bash. This is a helpful tool, but make sure you’re careful with the file paths here: Anything that meets the criteria you enter in will be deleted.
Before you continue, read yesterday’s tutorial to get caught up. This tutorial assumes you’re somewhat familiar with Automator and with the concept of the OS X command line (basically, that you know it exists).
- Open Automator, select Calendar Alarm from the new document picker, then click Choose.
- Click on Utilities in the left hand panel.
- Select Run Shell Script, then double-click it to add it to your workflow.
- In the panel that comes up put in the following code:
#!/bin/bash
thisUser="$(whoami)"
find "/users/$thisUser/OldDownloads" -mtime +30 -delete
- Click File -> Save and name your event.
- Calendar will open and will create a new event at the current time. Edit the Calendar event and set the appropriate repeat frequency to once a month, and you’re all set.