I am writing my own non-ObjC framework around Cocoa Scripting (think of writing a scriptable Mac app in C, C++ or Java, or in my case, Xojo).
I like to be able to intercept any Object-first method invocation instead of having to add the actual method to the ObjC class (I can't because the framework won't know which message the app code can handle in advance - so it'll instead have to receive and pass on any command message once they come in from the scripting engine).
For instance, any property getters and setters can be intercepted via implementing
-valueForUndefinedKey:
-setValue:forUndefinedKey:
as well as all the methods of the NSScriptKeyValueCoding protocol.
I am looking for a similar way to intercept NSCommandScript messages sent to the method specified in these sdef elements:
<responds-to command="reload">
<cocoa method="reloadList:"/>
</responds-to>
So, instead of implementing reloadList: by adding it to the class methods, I wonder if there's a generic way to catch all such calls.
I found that the class method
+ (BOOL)resolveInstanceMethod:(SEL)sel
gets invoked asking for reloadList:. But the same method is invoked for many other purposes as well, and so I rather not blindly intercept every such call because it would cause a rather severe performance hit if I'd forward them all to a Java function that tells me whether it wants to handle it, for instance.
I hope there's something that lets me tell that this selector is related to a NSScriptCommand before forwarding it further.
If it's not a Cocoa-based app then you're probably best to forget about using Cocoa Scripting as it's heavily coupled to the rest of the Cocoa architecture, install your own AE handlers directly using
NSAppleEventManagerand write your own View-Controller glue between those and whatever you eventually implement your Model in. See also: Scriptability (AppleScript) in a Mac Carbon applicationETA: Come to think of it, you might want to rummage around the web and see if you can dredge up any old C++ AEOM frameworks, as ISTR there were one or two around back in the pre-OS X days. May require some updating, and may or may not be any good (but then CS is rather crappy too), but it'd be far easier than starting completely from scratch as designing and implementing a good, robust, idiomatic (or even simplified) AEOM framework is a giant PITA, even when you do know what you're doing (and hardly anyone does).