1

I often download images, take screenhots, and save files that I am only going to use for a little until it can be discarded.

I want to create a folder which deletes the contents inside it every few days ad midnight to conserve space on my mac.

My original idea was to create a cron job to empty the folder at a specific time, but a problem exists.

My computer is a MacBook, and will not be powered on during the times that I want the files to disappear, this means I need these files to delete when I power the device back on (or wake from sleep) given the time has expired.

Any solution?

1

The solution is simple. Instead of creating a cron job, create a launchd plist (property list). Go to http://launched.zerowidth.com for help configuring common options and installing the plist. More options not included in the website can be found in the man page "launchd.plist" (by typing man launchd.plist), but you should be good to go with what's provided. The advantage is that launchd will run the plist when the computer turns on, if the computer was turned off at the time it was supposed to run. It'll even coalesce multiple events into a single event, if the script would have normally ran a few times while the computer was off.

1

Yes, if you want to create a cron job to empty the folder, it is a little intricate. I would also recommend creating a launched plist. It's efficient.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .