In my app I have a list of files, and the ability to delete one or more, for those people who dont know how to use Finder or Explorer.
But folderitem.delete is immediately destructive, and there will always be the ones who click 'delete’, answer ‘Yes I really mean it’, and still want the file back later when they realise it was a mistake.
Is there a reliable way to put a file into the trash so that it can be recovered by OSX or Windows?
Item.MoveFileTo SpecialFolder.Trash is the usual answer. It’s not clear whether it follows the same volume as the original item, but no one ever answered that after various users asked. It’s still the most common answer.
With the MBS plugin, you have MacFileOperationMBS.MoveToTrash.
Not off the top of my head, but there were problems years ago when I was building Plugins Pro. Generally, when there’s an API to do things and you choose the hacky way, you’re going to see problems at some point.
IIRC the Trash folder is locked for 3rd Party apps by default ( including the Terminal ) on recent versions of the macOS.
Last time I investigated this, it was actually preferable to use AppleScript over the API. The main reason is that using AppleScript to make Finder do it, enabled “Put Back”, allowing the customer to restore the file back from the trash, to where it was before.
That might have changed now.
I also vaguely recall something about you can use dragitems, so the customer can drag the file from your application into the trash and this bit gets fuzzy, but I seem to recall that the OS would then move to the file to trash for you.
Generally speaking, you shouldn’t rely on the Finder being available to perform these functions, unless of course your application is specifically designed to only work if the Finder is running. For the general case of moving an item to the trash, use the API.
It’s also poor form to do an operation in the background that disrupts the user’s expectation of what Undo will… undo.