If you experiment with reading/setting the OSX input language through the ObjC bridge, writing snippets like:
(function () {
'use strict';
ObjC.import('Carbon');
ObjC.import('stdio');
var sourceList = $.TISCreateInputSourceList(null, false);
var current_source = $.TISCopyCurrentKeyboardInputSource();
var cfs = $.TISGetInputSourceProperty(current_source, $.kTISPropertyInputSourceID);
var cfn = $.TISGetInputSourceProperty(current_source, $.kTISPropertyLocalizedName)
var sourceCount = $.CFArrayGetCount(sourceList)
return $.CFArrayGetValueAtIndex(sourceList, 0)
})();
we soon get obj reference return values of CF types. In ObjC itself these can be coerced to NS values. Any sense of how that can be achieved in JavaScript for Applications ?
(I am getting CF object reference return values from which I haven't succeeded in extract string or other primitive values)
You can coerce a CF type to an NS type by first re-binding the CFMakeCollectable function so that it takes 'void *' and returns 'id', and then using that function to perform the coercion:
ObjC.bindFunction('CFMakeCollectable', [ 'id', [ 'void *' ] ]);
var cfString = $.CFStringCreateWithCString(0, "foo", 0); // => [object Ref]
var nsString = $.CFMakeCollectable(cfString); // => $("foo")
To make this easier to use in your code, you might define a .toNS()
function on the Ref prototype:
Ref.prototype.toNS = function () { return $.CFMakeCollectable(this); }
Here is how you would use this new function with the TIS* functions:
ObjC.import('Carbon');
var current_source = $.TISCopyCurrentKeyboardInputSource();
var cfs = $.TISGetInputSourceProperty(current_source, $.kTISPropertyInputSourceID);
cfs.toNS() // => $("com.apple.keylayout.US")