
On Mon, Dec 29, 2014, at 13:58, Andrew Barnert wrote:
There isn't really a low-level function for it on any platform but maybe Windows, except rename, which is already there.
The Windows function for this is SHFileOperation, which isn't really low-level (but doesn't require a message loop).
On OS X, unless you want to use higher-level CoreFoundation APIs that require a runloop, you just look up the name of the trash directory (which I believe is theoretically localized but actually always ~/.Trash on the drive with your user directory, $mnt/.Trash otherwise)
Is it not uid-specific? Windows and XDG trash directories are uid-specific. A google search shows that it's $mnt/.Trashes/$uid.
And I don't know what the right thing to do on OS X would be for a file on a different filesystem than the user's home that doesn't have its own .Trash or is mounted read-only or no-trash.
If it's mounted read-only, you have a bigger problem. Another possible issue could be: bad permission on trash directory, bad permission or nonexistent parent directory that trash directory must be created in (home or .Trashes). These are also all issues that must be faced for XDG. XDG has a database of original location and deleted date for files in the trash - does OSX? (according to the tool I found, it does, at least for original location, but only works if you use Finder to trash the files)
Finder gives you a popup in each of those cases asking if you want to delete it immediately because it can't be trashed. And similarly for Linux, but the details are different (especially since you might not even have a home trash).
Another option would be to just script Finder with osascript. The tool http://hasseg.org/trash/ has objc code to "directly" script Finder without actually going through osascript. When it does not use Finder, it uses FSMoveObjectToTrashSync, which seems to be depreciated.