簡體   English   中英

inDesign腳本:在腳本文件中包含遠程.js文件(並使用它的變量)

[英]inDesign scripting: Include remote .js-file in script-file (and use it's variables)

我試圖在inDesign腳本中訪問遠程.js文件以使用它的變量。 我發現了在本地包含js文件的函數,但是還沒有找到一個很好的包含方法。

http://remote-site.com/test.js

var testVar = "it works!";

myscript.js,包括本地(工作):

app.doScript(new File("/Users/Popmouth/test.js"));
alert(testVar);

myscript.js,包括本地(包括遠程)(不起作用):

app.doScript(new File("http://remote-site.com/test.js"));
alert(testVar);

錯誤信息

我也找到了此代碼段,此警報有效(警報文件的內容,即“ var testVar =“ it work !;”。),但我不知道如何在下面的警報功能中使用var:

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

該功能

好的,所以我去了adobe論壇,並得到了以下字符串,它替換了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);  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM