The trash "Put Back" feature doesn't work with programmatically trashes files

Number:rdar://41878624 Date Originated:06-Jul-2018 11:50 AM
Status:Open (Duplicate of 45474030) Resolved:
Product:macOS + SDK Product Version:10.14
Classification:Other Bug Reproducible:Always
When using `[NSFileManager trashItemAtURL:resultingItemURL:error:]`, the originating path is not stored in the .DS_Store file, causing the `Put Back` option not to be shown for programmatically trashed files.

Steps to Reproduce:
 Create a file called `foobar`, then compile and run the below:

@import Foundation;

int main() {
    @autoreleasepool {
        NSFileManager *fm = [[NSFileManager alloc] init];
        NSError *err;
        NSURL *url = [NSURL fileURLWithPath:@"foobar"];
        NSURL *result;

        if (![fm trashItemAtURL:url resultingItemURL:&result error:&err]) {
            fprintf(stderr, "%s\n", err.localizedDescription.UTF8String);
            return 1;

        NSLog(@"now at: %@", result);

    return 0;

Then go to the Trash, right-click the `foobar` file, and notice how "Put Back" is not there.

Expected Results:
I expected the `foobar` file in the trash to show the `Put Back` context menu option.

Actual Results:
The `Put Back` menu item is missing and the file doesn't show up in `.DS_Store`.


It's reproducible with macOS 10.14 beta 3 and all the way back to at least 10.11.

More info:


Apple Developer Relations

Engineering has determined that your bug report is a duplicate of another issue (45474030) and will be closed.

The open or closed status of the original report your bug was duplicated to appears in a text box within the bug detail section of the bug reporter user interface. For security and privacy reasons, we don't provide access to the original bug yours was duped to.

By sindresorhus at Nov. 8, 2018, 6:57 a.m. (reply...)

It should also be noted that the following API also doesn't work:

No "Put Back" context menu option appears, even though the API clearly states that it: "Moves the specified URLs to the trash in the same manner as the Finder".

Bear in mind that the above API is best called from within a Cocoa app to ensure it's on the correct DispatchQueue, etc.

By acheronfail at July 6, 2018, 5:09 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!