0

I need a very simple example to call my local installed node.js and all the installed modules from AppleScript or JXA (JavaScript Application Scripting).

I tried in JXA:

 var app = Application.currentApplication()
 app.includeStandardAdditions = true

 const request = require('request-promise');
 const cheerio = require('cheerio');

 const URL = 'https://www.example.com';

 (async () => {

 const response = await request({...

Maybe it's easier in Applescript. But how can I call all this in AppleScript?

Thanks for an easy example and your help!

Towkir
  • 3,889
  • 2
  • 22
  • 41
donpasquale
  • 115
  • 1
  • 11
  • It's unclear from your wording whether you are 1. just wanting to load pure JS, or 2. wanting to actually invoke Node APIs. The second you can't do in any simple way. And I do not know enough about cheerio or request-promise to know whether they use Node.js-specific APIs. – David P. Caldwell Jun 15 '19 at 18:12
  • Also, it's "JXA," not "JAX." – David P. Caldwell Jun 15 '19 at 18:13
  • I discovered I could edit and fix the JXA/JAX part so hopefully that'll be approved soon. I also added the jxa tag to help get it in front of that audience. – David P. Caldwell Jun 15 '19 at 18:14
  • Although JXA and node.js are both javaScript, their environments are **very** different. They are not compatible. It would be easier to have your appleScript/JXA invoke your node.js code as a shell script. It could return a nice JSON response. PS I use JXA, node.js, and Cheerio on a daily basis. – JakeCigar Jun 15 '19 at 20:43
  • Thank you so much guys. JakeCigar, are there any simple exaples to Call node.js from AppleScript? I just wann call a function from my own javascript which is using node.js and it gives me back a value i wanna use in AppleScript. – donpasquale Jun 16 '19 at 05:31
  • `do shell script "/usr/local/bin/node /path/to/script.js " & quoted form of arg1 & space & quoted form of arg2 …` – foo Jun 18 '19 at 21:18

0 Answers0