The life changing magic of tidying up your download files
Marie Kondo is author of a popular book called The Life-changing Magic of Tidying: A Simple, Effective Way to Banish Clutter Forever. Tim Harford talks about one of the tricks of the book: you should flip your status quo, so that your default behavior is to throw things out, and you have to explicitly decide if you want to keep something.
Confession time: I don’t do this in everyday life with physical objects. I have far too many old T-shirts, for example. However, I absolutely do use the trick with my computer files.
Maybe you have a download folder like this:
That’s not mine, it’s what Shane Robinson’s downloads folder looked like. My downloads folder only has 12 files in it, because every now and again I run an AppleScript which does something fairly simple: It takes every file that’s been in the downloads folder for more than 2 weeks, and puts it in the trash.
I also do the same to a second folder, which I call Temporary. I use this folder for all the random mid-workflow files I have to create. If I have to pull a photo through multiple applications, ~/Temporary is where I store the intermediate TIFF or PNG files. If I’m working on an article like this one, I put a text file in the Temporary folder. You get the idea.
So if I want to keep any of the temporary files generated by the process of doing whatever I’m actually trying to do, I need to move them out of the Downloads or Temporary folders, and find a proper place for them.
Coming up with the script was a pain. I hate AppleScript. In the end I used Automator to fetch the files from the folders, and then told it to run a much smaller chunk of script on each of them. Here’s the script piece:
on run {input, parameters}
set maxDaysOld to 14 -- this is the number of days of stuff to keep
set oldFiles to {}
set oldFilesRef to a reference to oldFiles
repeat with n from 1 to length of input
set thing to item n of input
set dateAddedString to (do shell script "mdls -name kMDItemDateAdded -raw " & quoted form of POSIX path of thing)
set dateadded to the (date dateAddedString)
set daysold to ((current date) - dateadded) / 86400
if daysold > maxDaysOld then
copy (item n of input) to the end of oldFilesRef
end if
end repeat
return oldFiles
end run
The “clever” part is where it calls mdls
, which is the command-line interface to OS X’s Spotlight metadata database. The kMDItemDateAdded
property is OS X specific, not related to any underlying POSIX metadata, and records the date and time when the file was added to the enclosing folder.