MBS? How to get the "Put Back" feature to work in macOS

I am creating a small personal tool that removes/moves files to the trashcan.
For doing this, I use the FolderItem.delete methode and it works, except the “Put Back” option is not available.
When I try to use an Applescript using Finder to delete the files it does work as expected.

But I want to avoid Applescript (for various reasons).

My questions:
How can I send a file to the trashcan that enable “Put Back”? Why does the FolderItem.Delete not enable this by default? Is the Xojo Framework using non-macos-compiant ways to remove files?
Maybe with a macOS API declare? Maybe the MBS plugins can help here?

Thanks in advance.

In the “good old” Mac OS days, the “put back” location was actually stored with a file, in the directory.

Nowadays, however, Only Apple’s Finder knows about the Put Back location. Or maybe it’s stored in some secret file, like .DS_Store. Certainly nothing that we can easily access, AFAIK.

So, AppleScript (or AppleEvents, which is effectively the same) may be your only solution, as only that lets the Finder perform the operation (along with making sure the file is renamed in the Trash if necessary, and asking the user for permissions if needed).

Oh, wait. See this: https://stackoverflow.com/a/27847797/ - I believe MBS has this function available. Give it a try (you can try MBS plugins without payment as long as you only run it in the debugger).

Thank you for your answer.
Unfortunately, I could not find this in the MBS plugins. I don’t think it is available with those plugins.

The function has a really bad name: https://www.monkeybreadsoftware.net/cocoa-nsworkspacembs-shared-method2.shtml#1 .

That’s not working (no ‘put back’ available).
But the link Thomas showed is not using that API.

The move to trash methods may set it. But if Apple has bugs in api, I can’t do much.

I cannot find the move to trash methodes. Can you provide a working code example?

I usually copy from my FAQ:

That does send a file to the trash but does not enable the ‘Put Back’ option.

It works in Xcode with trashItemAtURL, that isn’t available in the MBS plugins.

I can add it for you…

In xDev 15.16; I wrote an article about deleting files, and I used the droids function that you’re looking for. http://xdevmag.com/

it’s already there on NSFileManagerMBS class:

shared method trashItem(file as folderItem, byref Resulting as folderItem, byref error as NSErrorMBS) as boolean