3 ms·
I don't know about PyObjC, but JXA is very awkward when coming from JS: it brings in conventions from Objective-C, and it's not explained anywhere what patterns
by aasasd 5y ago
I don't know about PyObjC, but JXA is very awkward when coming from JS: it brings in conventions from Objective-C, and it's not explained anywhere what patterns I'm supposed to use. E.g. with collections, it seems that instead of just values, you get some very lively views that change while you're trying to use them and refuse to act the same on subsequent access—so the robust way to get values from a collection repeatedly is to obtain the collection each time anew (or convert it to a sane Array). You have to figure out by yourself how AppleScript is translated to JS—or, more realistically, by copying examples from the web. Either I didn't find the proper documentation, or it's pretty much nonexistent. As the article mentions, the Github repo is the primary knowledge compendium on how the hell one uses JXA.
It's pretty much impossible to casually write JXA scripts now and then, just knowing JS and consulting reference docs—instead, it seems that you'll have to learn arcane ObjC conventions from the 80s and keep translating those to JXA, without much help from Apple. Add to this that Swift/ObjC docs themselves seem terse, done with a hefty bit of ‘fuck off’ attitude, and are more of ‘here's what we have’ reference with too little of ‘here's how to do the thing you want’. IIRC Swift docs just drop pages on old versions of classes and functions, so when Apple keeps rearranging things again in new versions, and you inevitably have old examples from the web, you have to grope for how each change works, instead of just opening the deprecated page and reading there that this new thing is now used.
So you have to translate JS ← JXA ← AppleScript ← Swift/ObjC, with resistance on every step.
Oh, and the system settings? I haven't seen comprehensive docs on them either. Just apple.stackexchange and a bunch of howto sites. I guess Apple prefers to provide living for these sites instead of spending some of the billions on a technical writer.
- aasasd 5y agoA, and by the way. Inevitably with a decent and widespread language you want to use third-party libraries, especially seeing as there are thousands upon thousands of them by now. Well, apparently you can load ‘compiled’ .scpt libraries—presumably done in either AppleScript or Javascript—but you can't just load a JS module from a file. There's a project that wraps JXA and uses Browserify to cram additional libraries down JXA's throat by merging them with the main script: https://github.com/johnelm/node-jxa https://github.com/johnelm/node-jxa