Make Trash work properly

15 March 2013, 10:00

If you’ve ever delved into the Trash to fish-out a deleted file, you’ll know it has an irritating limitation — there’s no way of knowing WHEN a file was deleted.

Files dragged to the Trash aren’t updated when they’re put there, so carry across the date stamps they previously had — a file last modified on 1st June 2010 will still show that date in the Trash, even if it was deleted yesterday. And if you’ve trashed several versions of disneyland.jpg, there’s no reliable way of knowing which of them is the one you most recently deleted.

There is a Date Added column within Finder that you can sort by but in my experience this doesn’t actually show when the files were added to the Trash! In fact, with most files all that appears is two dashes (—).

Below is one solution to this issue. It uses a folder action to automatically update the date stamp on each file that you put in the Trash, so you can then simply sort by the standard Date Modified column in the Finder window to see the most recently deleted files.

1. Start by opening Terminal, which you’ll find in the Utilities folder of the Applications list of Finder. Type the following, then quit the Terminal window:

mkdir -p ~/Library/Scripts/Folder\ Action\ Scripts/

2. Open AppleScript Editor, which you’ll also find in the Utilities folder of the Applications list in Finder. Then start a new document if one isn’t already visible, and paste in the following code:

on adding folder items to this_folder after receiving added_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

Click the Compile button to ensure the script is OK — if it is the script will be colorised and indented. If not you’ll see an error.

3. Click File → Save and tap Shift+Command+G. In the dialog box that appears, type ~/Library/Scripts/Folder Action Scripts and click Go. Then type the filename Trash date stamper in the Save As dialog box, selecting “Script” in the File Format drop down. Save the file, then quit AppleScript Editor.

4. Right-click any folder anywhere, and select Folder Actions Setup (you may have to click Services → Folder Actions Setup). Click Cancel on the dialog box that appears offering a list of scripts.

5. In the Folder Actions Setup window, put a check alongside Enable Folder Actions if there’s not one already there. Then at the bottom left click the Plus icon and, in the dialog box that appears, tap Shift+Command+G and type ~/.Trash. Then click Go in the dialog box, then the Open button in the parent dialog box.

6. Straight away you’ll see a list of folder actions. At the bottom will be your new script — Trash Date Stamper.scpt. Select this, and click the Attach button. Close the Folder Actions Setup dialog box when done.

That’s all that’s needed. From now one any files you drag to the Trash will have their “Date Modified” reset to the date and time at which you dragged them to the Trash. You can then select to sort by Date Modified by clicking that heading in List or Column view when you open the Trash to view its contents. Note that it takes a few seconds after you add a file to the Trash for the new date stamp to be applied.

Know better?