JXA to Insert Text in Current Application

In a JXA script how can I insert data into another app at the current position?

Currently I am doing this using TextExpander. This brief JXA script contains a function which returns the names of selected records. TextExpander inserts the returned value into my current app. Can the same be achieved in JXA without using TextExpander?

(()=> {
  const app=Application("DEVONthink 3");
  const names = app.selectedRecords.name();
  return names.join("\n");

Maybe. I found this
explanation for AppleScript, and that should directly translate to JXA.
You’d have to run the DT script from „the other“ app though, I guess. Or figure out what this app is before you run the script in DT. Something like

const curApp=Application.currentApplication();
const DTapp=Application("DEVONthink 3");
# use system events to send keystrokes 

I’m away from my Mac, so can’t test that.

1 Like

Thanks… that makes sense - I’ll figure out the system events syntax from there