I'm looking into things I can contribute to open source. One pain point I have with many FOSS apps I use is they don't support scripting. I'm thinking it would be nice to at least try to add some basic scripting support to some of the apps I use, e.g. OBS.
However, all the guides for adding scripting support assume that the app in question is written in Cocoa. A lot of these FOSS apps I'm looking at are… not. Does anybody have some good resources for exposing nonnative functionality to native system services, as would be required for scripting?
Implementing non-trivial Apple event support is a right PITA; massively so if you have to implement it from scratch in C/C++ (CocoaScripting.framework is a non-starter for non-Cocoa apps and any third-party frameworks will be massively out of date). Right now I wouldn't even try: AppleScript is dying and JXA is already dead, and Apple are silent on its plans (if any) for the future of Mac Automation. This may change if/when Shortcuts comes to macOS, but that won't happen before 10.15.
If you just want to add really basic automation support (i.e. no 'object model', just simple commands like play FILE
/convert FILE
) and the app plays nicely with the macOS event loop, it's not hugely difficult (though still extremely tedious) to install Apple event handlers and unpack and pack simple arguments and results (numbers, strings) via the old C Apple Event Manager API. It won't be very "AppleScript-ish", but at least it's achievable. Or, if the app already has its own built-in (e.g. JavaScript) scripting support, implementing a do script CODE [with parameters {ARG1,ARG2,…}]
handler to call into that is an easy win.
As far as documentation and example code goes, search for AEInstallEventHandler
and see what comes up. Won't be great, but that's as good as it gets. Be prepared to figure out a lot of this stuff for yourself.