You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automatically removing trash 5 days old

Hi

I did a secure empty trash yesterday which I have not done in a few years and there were over 1.5 million files to permanently erase. This is dangerous to keep this much trash and it takes way too long to clean up. I would prefer regular maintenance . . . to securly and automatically empty the trash regularly and still maintain the benefit being able to prevent accidental deletion of recent work. The requirement therefore would be to perhaps during off hours, once a day or upon startup automtically secure empty trash only items that have aged in the trash at least x days.


Can this be done quickly and simply with applescript or a cron job?

Posted on Jul 12, 2011 12:58 AM

Reply
37 replies

Jul 20, 2013 5:12 AM in response to Tony T1

OK, found a solution to fixing this. To change the file modification date to the date added to the Trash:


From: http://apple.stackexchange.com/questions/7947/sort-trash-files-by-date-trashed


Go to the AppleScript Editor, past in the following script and save it in /Library/Scripts/Folder Action Scripts

on adding folder items tothis_folderafter receivingadded_items

repeat with this_item in added_items

do shell script "touch -m " & quoted form of POSIX path of this_item

end repeat

end adding folder items to


Then right click on any folder in Finder, go to Services and click Folder Actions Setup go to /Library/Scripts/Folder Actions and select Configure Folder Actions. Cancel the dialog asking which script to attach. Click the checkbox to Enable Folder Actions, then click the plus sign to choose the recycle bin folder. Click CMD+SHIFT+G ( ( or hold CMD+SHIFT+. ) and type in ~/.Trash, click ok and then click open. Now on the right side click the plus sign to choose the AppleScript that you saved earlier.

Note: I changed do shell script "find " & quoted formofPOSIX pathofthis_item & " -exec touch {} \\; to do shell script "touch -m " & quoted formofPOSIX pathofthis_item

Jul 22, 2013 2:07 PM in response to Tony T1

Just realized that if a folder with files is trashed, then only the Folder will be touched.

So, the original script I linked was correct.

The correct script, that will touch recursively is:



on adding folder items tothis_folderafter receivingadded_items

repeat with this_item in added_items

do shell script "find " & quoted form of POSIX path of this_item & " -exec touch {} \\;"

end repeat

end adding folder items to

Sep 23, 2013 9:00 PM in response to Tony T1

It seems, it's not a good idea to set the date deleted using Folder Actions.

The Folder Actions technology is not suitable for heavy payload.

If you'll try to delete many files, hunders at the time, this script will executed many and many times and will miss some files.

I tried to delete about 4000 small files, many files remained in Trash with old date, and I got unclosing "Deleting to Trash" small Finder window, so I was forced to relaunch Finder. Later in Console I found multiple records with "Folder Actions respawn in...sec".

Please, be careful.

Automatically removing trash 5 days old

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.