Here's a script and launchagent that will do what you want:
First, copy the following into the Applescript editor, and save it as dated_deleter.scpt in (say) /Library/Scripts. Set the security level and days to wait properties to what you want.
property keyPhrase : "Trashed on: "
property securityLevel : 2 -- overwrites: 1=1-pass, 2=7-pass, 3=35-pass, see man srm
property daysToWait : 7
tell application "Finder"
-- get files in trash that are not new, and check dates
set oldFiles to (every item of trash whose comment contains keyPhrase)
set trashmeFiles to ""
repeat with thisFile in oldFiles
-- extract trashed date from the spotlight comments
set trashedDate to last item of my tid(comment of thisFile, keyPhrase)
try
-- check dates in a try block in case of weirdness)
if my checkDate(trashedDate) then
set trashmeFiles to trashmeFiles & " " & my makePosix(thisFile as alias)
end if
end try
end repeat
-- trash 'em in a subroutine
my trashEm(trashmeFiles)
-- gather new files
set newFiles to every item of trash whose comment does not contain keyPhrase
-- add the current date to the spotlight comment of the new files
repeat with thisFile in newFiles
set c to comment of thisFile
if c = "" then
set comment of thisFile to keyPhrase & short date string of (current date)
else
set comment of thisFile to c & return & keyPhrase & short date string of (current date)
end if
end repeat
end tell
on trashEm(fs)
-- set up proper security level
if securityLevel = 1 then
set cmd to "srm -rfsz"
else if securityLevel = 3 then
set cmd to "srm -rfz"
else
set cmd to "srm -rfmz"
end if
-- start a secure delete process in the background
do shell script cmd & fs & " &> /dev/null &"
end trashEm
on tid(input, delim)
-- generic subroutine to handle text items
set {oldTID, my text item delimiters} to {my text item delimiters, delim}
if class of input is list then
set output to input as text
else
set output to text items of input
end if
set my text item delimiters to oldTID
return output
end tid
on makePosix(f)
return quoted form of POSIX path of f
end makePosix
on checkDate(d)
return (date d) ≤ (current date) - daysToWait * days
end checkDate
second copy the following into a plain text file (use TextWrangler, or TextEdit in plain-text mode, don't use rich text), modify the /path/to/dated_deleter.scpt line so that it is a POSIX path to the script (if you use the above, that would be /Library/Scripts/dated_deleter.scpt) and save it as user.trash.dated.plist in ~/Library/LaunchAgents or /Library/LaunchAgents. (use the former if there's just one user on the machine; use the latter if you want it to apply to multiple users)
<?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>user.trash.dated</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>/path/to/dated_deleter.scpt</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>0</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>
Finally, open terminal and enter the command launchctl load /Library/LaunchAgents/user.trash.dated.plist (or alternately just restart the machine). Either of these will load the plist into launchd as a job, launchd will wait until midnight of each day (hour 0, minute 0) and then run the dated_deleter script. Basically the script writes the date into the items spotlight comments the first time it sees it in the trash, and then deletes it if the written date gets too old.
Two caveats:
- if you recover a file from the trash and then accidentally delete it again, it may be deleted next pass through unless you delete the key phrase from the spotlight comments. you can do that in the Finder get info window.
- I noticed in testing that if I copy a file, run the deleter on it, delete it, and then copy the same file again for a second test, spotlight remembers the comments applied to the first file. Somehow Spotlight recognizes that the new copy is identical to the old copy and retains information from the old - completely unexpected. This might be an issue in odd cases if you do lots of file duplicating; if so we'll need to add in a routine that deletes the key phrase from spotlight comments before the file gets deleted.