Do You like Your ~/Downloads folder ? Is it always clean and well organised ? Mine never was … Over time it got so messy that it was easier to download something again that look for it in ~/Downloads…
I came up with an idea of scheduled folder cleanup, but because in OS X cron is not available by default I had to figure it out the OS X way.
First I wrote a script for cleanup in ~/bin/download-cleanup :
#!/bin/bash find /Users/[username]/Downloads -mtime +30 -print0 | xargs -0 rm -rf
This script looks for files older than 30 days and deletes them.
Now lets schedule it. Create file under ~/Library/LaunchAgents/pl.jusz.gen.DownloadCleanup.plist
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-/Apple/DTD PLIST 1.0/EN" "http:/www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>pl.jusz.gen.DownloadCleanup</string> <key>ProgramArguments</key> <array> <string>/Users/[username]/bin/download-cleanup</string> </array> <key>StartInterval</key> <integer>43200</integer> </dict> </plist>
You can now register Your plist file with launchd:
launchctl load ~/Library/LaunchAgents/pl.jusz.gen.DownloadCleanup.plist
If You want to manually invoke Your script through launchd:
launchctl start pl.jusz.gen.DownloadCleanup.plist