How a Daily Purge Folder Changed My Life

I used to be just like you. I had a Downloads folder full of junk, and a desktop full of clutter. Screen shots, temp files, email attachments, and more filled my computer like leaves on the ground in autumn. Now and then I would try to clean up the mess, but it was a chore that all too often went undone.

Then I made a DailyPurge folder, and my whole life changed.

Now email attachments, screenshots, downloads, temp files, all that junk goes into a folder called "DailyPurge" in my home directory. And like magic (or having a competent night crew), every night the contents of that directory get moved into the trash, into a folder named with the date — for example, DailyPurge-2018-03-05. So my desktop stays clean, my DailyPurge folder stays clean, and on the rare occasion that I realize I actually want something that was in there, I can easily find it in the trash.

You can enjoy this luxury too! It just requires creating a folder, two little text files, and then configuring stuff to use the new folder.

First, create a folder in your home directory called DailyPurge.

Next, use your favorite text editor to make a "plist" file like the following (but replacing each occurrence of "jstrout" with the name of your own home directory):


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

This plist file should be pretty self-explanatory; it just specifies running a script called ".dailyJob" in your home folder, 3 minutes past midnight every day. Any normal output from that script is stored in ~/.dailyJob.log, and error output (if any) goes to ~/.dailyJob.err.

Now you need to save this in ~/Library/LaunchAgents as a file called local.dailyjob.plist. The "Save As" option may not show you the Library folder, because Apple thinks you are likely to screw things up if you muck about there. In that case, just save the file to your Desktop, then in Finder, use the Go To Folder... command, and enter ~/Library/LaunchAgents. That will open the correct folder in the Finder; drag your plist in.

Next, we need the script itself. This is just a shell script in your home folder called .dailyJob, which can do anything you want to happen on a daily basis. But here's mine, which simply empties the DailyPurge folder every day:


echo ".dailyJob running" $(date)

dest=~/.Trash/DailyPurge-$(date "+%Y-%m-%d")
mkdir $dest
echo "Moving to " $dest ":"
ls -la ~/DailyPurge
mv ~/DailyPurge/* $dest/

exit 0

Now you're basically set; log out and log back in, and your new LaunchAgents daemon will be ready to serve. (If you want to learn more about running periodic scripts with launchd, see this blog post.)

But to get the most out of your new DailyPurge folder, you'll want to configure various software you use to put its temp files there instead of on the desktop, Downloads folder, or whatever it's doing now. You can do that on an as-needed basis, but here are some tips to get you started:

  • Screen shots: these normally go to the Desktop; to change that requires a couple of Terminal commands, like so:
    defaults write location ~/DailyPurge
    killall SystemUIServer
    See here for more details if needed.
  • Downloads: these are set in the preferences of your web browser; in Firefox, it's in the "General" section under "Files and Applications". Just click the "Choose" button, and select your DailyPurge folder. You'll find something similar in the prefs for Safari, Chrome, or whatever other browser you prefer.
  • Attachments: Your email client will probably have a similar preference setting somewhere for a folder to use when you double-click an attachment to view it (especially if it's a compressed attachment). Let it save or unpack it into DailyPurge, so you don't have to worry about cleaning up after it.
  • Others: as you go about your daily Mac life, you'll run into other situations where you need to save some temp file — for example, printing a document to PDF just so you can send it as an email attachment. Save it to the DailyPurge folder, and then forget about it.

Pro Tip: drag the DailyPurge folder into your Favorites on the left side of any Finder window, and then it'll be easily accessible not only in the Finder, but also in any file (open/save) dialog.

So that's it! Make yourself a DailyPurge folder, and set up the script to ensure it gets purged daily. Life is good!