Which kind of javascript env does Automation run?


#1

(Choosing OmniPlan - OmniPlan for Mac for lack of a better selectable category).

Hi there.
I’m very interested in Automation for OmniPlan. I would like to know more about which kind of javascript enviroment our scripts get executed on. Is it a embedded nodejs? Which version?

Ultimately I’m trying to understand what can I do inside my scripts:

  1. Which javascript syntax can i use?
  2. If a superset of a nodejs version, can I import modules (for example, fs, so I can read local files in the filesystem; or https to make http requests)?
  3. Can I import npm modules somehow (external libraries)?

Thanks!


#2

No, not nodejs.

It’s a JSContext object:

https://developer.apple.com/documentation/javascriptcore/jscontext

No NodeJS access to the filesystem, and no DOM.

You can list the set of available top-level objects by evaluating

Object.keys(this)

in the Automation Console.

To narrow that down to the file API objects:

Object.keys(this).filter(s => s.includes('File'))

Which will yield:

[FileSaver, FileWrapper, FileType, FilePicker]

(details for each of which can be found in Automation > API Reference)


#3

PS you will also see a URL object with a fetch method.

See, for example: https://omni-automation.com/shared/url.html