1

I have my Mac configured to automatically delete objects 30 days after they have been moved to Trash (at Finder > Preferences > Advanced > Remove items from the Trash after 30 days).

However, I have files in Trash of which I think that they have been moved there more than 30 days ago. Now I'm wondering how macOS keeps track of when an item has been moved to Trash, and how I can check that?


Update

With regard to "where is the information stored", terminal command mdls is said to reveal meta data attributes of which one named kMDItemDateAdded is said to hold the date added value. However, I've tried a few files in my Trash, and none of them seems to have that attribute. Others I tried where ls -ale and xattr, but to no avail.

4
  • After your edit - Check the files manually - this may be tied to the Put Back value, which only exists if the files were thrown away by Finder, not by any other method. Test the files have a Put Back option if right-clicked in Trash. [idk where that is stored either]
    – Tetsujin
    Commented Feb 23, 2022 at 18:37
  • 1
    From experiment: mdls shows only very limited metadata for files in Trash - just file system metadata kMDItemFS..., not file content. Conclusion: Spotlight does not index the content and metadata of files in the trash. Hence: mdls will not show kMDItemDateAdded.
    – Gilby
    Commented Feb 24, 2022 at 4:28
  • 1
    @Tetsujin Yes, the files haven been moved to Trash via Finder, and do show a Date Added there, as well as a Put Back option, yet mdls doesn't show a kMDItemDateAdded property.
    – not2savvy
    Commented Feb 24, 2022 at 11:56
  • @Gilby You are right, kMDItemDateAdded is shown when I put back the file, and it disappears again after I move it to Trash. However, this means that mdls ist not suitable for showing meta data of items in Trash, but then what is?
    – not2savvy
    Commented Feb 24, 2022 at 12:01

2 Answers 2

5

There's a Date Added column if you open the Trash in Finder. If you don't see it, switch to List view Cmd ⌘ 2 , right click any header & add it from the list. Click any header to sort by it.

enter image description here

I don't know how to grab this data by any other method, but it's easy enough to either scroll down, or flip the list by clicking the header a second time, so oldest sorts to the top.

1
  • Fair enough, this answer is useful for checking, so thanks! Yet, I still hope to find out about where the information is actually stored.
    – not2savvy
    Commented Feb 23, 2022 at 18:15
0

This may not be the solution you are looking for, but you could create a Folder Action to attach to your "/Users/your_shortname/.Trash" folder which logs the file name and date of every item sent to the Trash.

This following AppleScript Folder Action code will create the file "Files_Added_To_Trash.log" on your Desktop, (if it does not already exist) and writes the file name and date it was added to the Trash folder, to it.

Paste this following code into a new Script Editor.app document and save it as "Log_Trashed_Files.scpt" to your "/Users/your_shortname/Library/Scripts/Folder Action Scripts" folder.

Saving the file to that location will make it available in your "Folder Actions Setup.app" and when right clicking on a folder in Finder and choosing "Folder Actions Setup"

property addedToTrashLog : (path to desktop as text) & "Files_Added_To_Trash.log"

on adding folder items to theFolder after receiving theNewItems
    --  Called after items have been added to a folder
    --  theFolder is a reference to the modified folder
    --  theNewItems is a list of references to the items added to the folder 
    repeat with thisFile in theNewItems
        set currentDate to (current date) as string
        tell application "System Events" to set theFile to name of thisFile
        set theText to theFile & " was sent to the Trash on " & currentDate
        do shell script "echo " & quoted form of theText & " >> " & ¬
            quoted form of POSIX path of addedToTrashLog
    end repeat
end adding folder items to

on removing folder items from theFolder after losing removedItemNames
    --  Called after items have been removed from a folder
    --  theFolder is a reference to the modified folder
    --  removedItemNames is a list of names of items removed from the folder
    
    (* You may want to add code to this section which removes the log entry
    from the "Files_Added_To_Trash.log" file for the files that get emptied from
    the Trash folder. *)
end removing folder items from

In Finder, simply right click on the .Trash folder in your Home directory and select Services/Folder Actions Setup... If you can't see the ".Trash" folder in your Home directory (/Users/your_short_name/.Trash) folder, clicking anywhere on your Desktop and then keyboard shortcut ⌘Command+⇧Shift+ . should un-hide all files.

enter image description here

Now, anytime a file is sent to the Trash, the name of that file and the time and date it was sent to the trash will be added to your "Files_Added_To_Trash.log" file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .