I am trying to translate a few Applescript (AS) into Javascript (JXA) for BBedit.
It's been a fun little thing to knock some rust off, but I'm stumped. With AS I can set an insertion point into a BBEdit document thusly;
tell application "BBEdit"
activate
tell text 1 of window 1
select insertion point before line 40
end tell
end tell
I'm totally stumped when it comes to JXA. I've been poking around in the line objects but I can't find a insertsionPoint property.
You can access selection properties like so;
currentLine = bbedit.selection().startline().
But it is read only. So I think you need access to that select method if you want to set a selection or insertion point. I have no clue how, or if you can with JXA.
Anyone know how to set a BBEdit insertion point and/or selection with JXA? Thanks.
JXA doesn't implement insertion reference forms (before
/after
/beginning
/end
). Relative (previous…
/next…
) and range (from…to…
) specifiers are also borked, and filter (whose…
) clauses are horrible too. Lots of non-trivial stuff that works fine in AS breaks in JXA: like Apple's earlier Scripting Bridge API, JXA was half-baked when shipped and immediately abandoned to rot.
Crap like this is why I recommend sticking to AppleScript. The language may stink, but it's the only [marginally] supported option that actually implements Apple events right. Normally I'd recommend calling into AppleScript from other languages via the AppleScript-ObjC bridge as the least sucky solution, but Apple have managed to break that too in 10.13.
(If you enjoy living dangerously, NodeAutomation provides non-broken Apple event support for Node.js, but with Apple abandoning AppleScript automation I don't want to waste anyone's time promoting or supporting it, so caveat emptor.)