Copy link to clipboard
Copied
'm trying to access a remote .jsfile within an inDesign script to use it's variables. I found functions for including js-files locally but haven't found a good way to include.
http://remote-site.com/test.js:
var testVar = "it works!";
myscript.js, including locally (working):
app.doScript(new File("/Users/Popmouth/test.js")); alert(testVar);
myscript.js, including locally including remotely (not working):
app.doScript(new File("http://remote-site.com/test.js")); alert(testVar);
I also found this snippet, this alert works (alerts the content of the file, i.e. "var testVar = "it works!;") but I don't know how to use the vars in my alert function below:
var HTTPFile = function (url,port) {
if (arguments.length == 1) {
url = arguments[0];
port = 80;
};
this.url = url;
this.port = port;
this.httpPrefix = this.url.match(/http:\/\//);
this.domain = this.httpPrefix == null ? this.url.split("/")[0]+":"+this.port :this.url.split("/")[2]+":"+this.port;
this.call = "GET "+ (this.httpPrefix == null ? "http://"+this.url : this.url)+" HTTP/1.0\r\nHost:" +(this.httpPrefix == null ? this.url.split("/")[0] :this.url.split("/")[2])+"\r\nConnection: close\r\n\r\n";
this.reply = new String();
this.conn = new Socket();
this.conn.encoding = "binary";
HTTPFile.prototype.getFile = function(f) {
var typeMatch = this.url.match(/(\.)(\w{3,4}\b)/g);
if (this.conn.open(this.domain,"binary")) {
this.conn.write(this.call);
this.reply = this.conn.read(9999999999);
this.conn.close();
} else {
this.reply = "";
}
return this.reply.substr(this.reply.indexOf("\r\n\r\n")+4);;
};
}
var hyle = new HTTPFile("http://remote-site.com/test.js ");
alert(hyle.getFile());
hyle.getFile();
This one works from a real remote.
It's Mac only I'll see about Windows for the sake of compleatness
...var remoteCode = 'https://gist.githubusercontent.com/Trevor-/a297b25e270c2e19d3ba12b5406212d9/raw/88837413a0d5a234ad257bfc63c79f3fb3f87a25/gistfile1.txt';
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",
Copy link to clipboard
Copied
Accident in:
blah (testVar, 'bar');
is on :
app.doScript
somebody help me?
Copy link to clipboard
Copied
Same for me! Working fine.