Copy link to clipboard
Copied
Hello,
I wonder if it's at all possible to talk to an external JavaScript API from an InDesign script? Particularly, I'd like to use this calendar module to get supported countries and then holiday names for a chosen country and year. I'd like to use an external library due to it being constantly updated.
I found the below piece of code but am unsure how it should be modified to work with the above API. Any help or similar examples would be much appreciated. BTW I'm on a Mac.
var remoteCode = 'http://remote-site.com/test.js'; //location of your remote file
var script = app.doScript("do shell script \"curl 'remoteCode'\"".replace("remoteCode", remoteCode), ScriptLanguage.APPLESCRIPT_LANGUAGE);
// Set script args
app.scriptArgs.setValue("scriptArg1", "Hello");
// Set environmental vars
$.setenv("envVar1", "World");
// Run the "remote" script
app.doScript(script, ScriptLanguage.JAVASCRIPT);
Copy link to clipboard
Copied
So I've been trying to pass some variables around and got an early sucess.
Local JSX:
var remoteCode = 'https://someserver.com/remote.js';
var script = app.doScript("do shell script \"curl 'remoteCode'\"".replace("remoteCode", remoteCode), ScriptLanguage.APPLESCRIPT_LANGUAGE);
var data = ["OK", 2021];
app.doScript(script, ScriptLanguage.JAVASCRIPT, data);
alert(response);
Remote JS:
var incoming = data != null ? data : "error";
var response = "response: " + incoming;
It looks like I would be able to extend both scripts to get the information I need.
Just for clarification, what do the below lines do?
// Set script args
app.scriptArgs.setValue("scriptArg1", "Hello");
// Set environmental vars
$.setenv("envVar1", "World");