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 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:


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!