Closed erikjalevik closed 6 years ago
where do you get the filePath
from?
Oh that's just a local string to a full, absolute path.
For this test, I used:
/Users/ejal/dev/filur/sandbox/test target/.gitignore
i found the bug and fixed it (the new version is already pushed to npm, not sure how long it takes to propagate but you can fix it for the time being by using this workaround):
// instead of objc.ns([nsUrl]);
const nsArray = NSMutableArray.array();
nsArray.addObject_(nsUrl);
you probably should replace the -[NSWorkspace recycleURLs:completionHandler:]
call with -[NSFileManager trashItemAtURL:resultingItemURL:error:]
. The first one is asynchronous and requires a properly set up run loop (which you'd need to do manually and which probably wouldn't be trivial). The NSFileManager
one is synchronous, which means that you can simply call it w/out having to implement anything else to make it work:
const trashUrl = objc.allocRef();
const error = objc.allocRef();
const success = NSFileManager.defaultManager().trashItemAtURL_resultingItemURL_error_(nsUrl, trashUrl, error);
Amazing. Thanks for the quick turnaround.
I verified that both the NSMutableArray
approach and the updated 0.16 version work.
Thanks for the hint about NSFileManager
too. Seems like it's the more modern approach.
👍
First of all, big thanks for putting this library together. I was looking hard and long for something up-to-date for calling native Mac APIs and only discovered this through a comment hidden beneath a SO question.
I'm trying to use it to send an item to the Trash on MacOS via
NSWorkspace.recycleURLs
, but I'm not sure I've quite got the hang of how to pass arguments into Cocoa functions. The method is expecting an NSArray of NSURL objects, but whatever I do, the call fails with the error:Since
isFileURL
is a method onNSURL
, I draw the conclusion that Cocoa somehow gets a dictionary instead of anNSURL
on which it tries to callisFileURL
.I've tried various different ways of creating the array, but no luck so far. Here is my code:
What am I missing?