OS X – Scheduled files cleanup

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

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s