I've recently learned about the existence of JavaScript for Automation. More interesting to me is the ability to call into Objective-C APIs, subclass Objective-C classes in JavaScript, and the ability to pass objects of JavaScript-implemented subclasses back to Objective-C APIs who use the parent class as an interface definition.
The biggest problem I have is that I don't exactly know Objective-C, and I know this. That's part of the reason I'm using JXA for this (the main reason being I find the fact you can even do this all with JavaScript for Automation to be quite intriguing.)
I also don't know the Cocoa API, but am attempting to learn it via JXA.
So, how would I go about creating and populating a JavaScript window using JXA?
The code I have so far is:
ObjC.import('Cocoa');
var frame = $.NSMakeRect(100, 100, 200, 200);
var styleMask = $.NSMiniaturizableWindowMask |
$.NSClosableWindowMask |
$.NSTitledWindowMask;
var rect = $.NSWindow.contentRectForFrameRect = frame;
rect.styleMask = styleMask;
var window = $.NSWindow.alloc.initWithContentRect = rect;
window.styleMask = styleMask;
window.setBackgroundColor = $.NSColor.blueColor;
There's almost no examples out there, aside from the snipplets Apple provides with the JXA documentation on the Objective-C bindings.
So can someone show me how to come up with a basic window, and maybe a label, textbox, and button, with JXA?