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

Originator:sindresorhus
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
 
Summary:
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:

```objective-c
@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`.

Version:
10.14

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

More info: https://github.com/sindresorhus/macos-trash/issues/4

Comments

It should also be noted that the following API also doesn't work: https://developer.apple.com/documentation/appkit/nsworkspace/1530465-recycleurls?language=objc

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 bugreport.apple.com 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!