0

I'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);

Error message

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 remoteFile = new HTTPFile("http://remote-site.com/test.js");
alert(.getFile());

This function

pjpscriv
  • 866
  • 11
  • 20
Carl Papworth
  • 1,282
  • 2
  • 16
  • 35

1 Answers1

0

Ok, so I went to adobe-forums and got the following string which replaces app.doScript(new File("/Users/Popmouth/test.js"));:

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);  
Carl Papworth
  • 1,282
  • 2
  • 16
  • 35