Ok, did some digging and here's what's going on, as far as I understand it.
runPluginCommandWithIdentifier_fromBundleAtURL calls an
hasExtension method for
url, which is defined in
NSURL+BCFoundation (BCFoundation is a library we use to define some prefixes and utility methods for Sketch, that extend Apple's Foundation framework).
If you open Sketch's Run Script panel and run this code:
you'll get this result:
<MOMethod: 0x608000036840 : target=0x608000a7fe40, selector=hasExtension:>
as expected. However, when you try to run that code from
coscript, it fails miserably because coscript has no notion of what BCFoundation is. SketchTool, on the other hand, includes BCFoundation, so running the code using
sketchtool run gives you the expected output.
However, it looks like you need to run code in Sketch without bringing it to the foreground. So the question is… do we change the implementation for
runPluginCommandWithIdentifier_fromBundleAtURL so that it doesn't use
hasExtension? Or would it be better if we added a command line option to
sketchtool to keep Sketch in the background when running scripts? Hint: the second option is way easier and more future proof, since
sketchtool run will load BCFoundation (and other libraries)…