(Choosing OmniPlan - OmniPlan for Mac for lack of a better selectable category).
Ultimately I’m trying to understand what can I do inside my scripts:
- 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)?
- Can I import npm modules somehow (external libraries)?
No, not nodejs.
It’s a JSContext object:
No NodeJS access to the filesystem, and no DOM.
You can list the set of available top-level objects by evaluating
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)
PS you will also see a URL object with a
See, for example: https://omni-automation.com/shared/url.html
Thank you, draft8! Sorry for my delayed response here.
That takes care of #2 and #3 I suppose.
Any help appreciated, thanks!
The interpreter provided by a JSContext instance is that used by the JSC of the given macOS version, and is essentially that of the version of Safari current at the macOS release.
(You can’t, of course, update the system JSC by installing a later version of Safari)
Grosso modo, it will certainly be a highly compatible ES6 (omniJS is not available on earlier macOS versions), and finer-grained specifics should show up in the Safari columns here:
PS if you are referring to JXA (which reaches back further than omniJS) it will be ES6 from Sierra onwards, ES5 for the preceding macOS, and absent in any form before that.
The JXA column at https://kangax.github.io/compat-table/es6/ gives a conservative lowest common denominator (macOS Yosemite) view.
(In practice you can use highly compliant ES6 in the JXA of Mojave + Catalina)
That’s perfect! Thank you, @draft8. You rock.