• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Include remote .js-file in script-file (and use it's variables)

Explorer ,
Sep 20, 2018 Sep 20, 2018

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

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

alert(hyle.getFile());

hyle.getFile();

TOPICS
Scripting

Views

5.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Sep 20, 2018 Sep 20, 2018

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",

...

Votes

Translate

Translate
Explorer ,
Dec 11, 2020 Dec 11, 2020

Copy link to clipboard

Copied

LATEST

Accident in:

 

blah (testVar, 'bar');

is on :


app.doScript

somebody help me?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 20, 2018 Sep 20, 2018

Copy link to clipboard

Copied

Same for me! Working fine.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines