Skip to content

Instantly share code, notes, and snippets.

@sirlancelot
Created March 5, 2010 21:34
Show Gist options
  • Save sirlancelot/323181 to your computer and use it in GitHub Desktop.
Save sirlancelot/323181 to your computer and use it in GitHub Desktop.
This is a launchd script that will watch my "Downloads" folder and automatically trash files that are over 14 days old. A log of the trashed files is kept in the Console Messages. NOTE: Files are moved to the trash and can be recovered from there.
1. Edit the `EnvironmentVariables` and `WatchPaths` to point to your profile. (NOTE: unless you change
the `ProgramArguments`, you MUST keep the "Downloads" folder the same.
2. Move the file in to your `~/Library/LaunchAgents` folder.
3. Log out and back in.
If you want, open up Console.app and watch "Console Messages" for files that were trashed. an example
message looks like:
3/5/10 1:30:43 PM me.mpietz.Trash-Old-Downloads[9828] /Users/mpietz/Downloads/test -> /Users/mpietz/.Trash/test
<?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>me.mpietz.Trash-Old-Downloads</string>
<key>EnvironmentVariables</key>
<dict>
<key>HOME</key>
<string>/Users/mpietz</string>
</dict>
<key>WatchPaths</key>
<array>
<string>/Users/mpietz/Downloads</string>
</array>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>/usr/bin/find $HOME/Downloads -mtime +14 -exec mv -v &apos;{}&apos; $HOME/.Trash \;</string>
</array>
<key>KeepAlive</key>
<false/>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment