Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between app.doScript and $.evalFile?

The only difference I have found so far: If a script that is run by app.doScript returns an error, the file and line number of the error are overridden by the file and line number of the app.doScript call.

Are there any other differences I should know about?

Here's sample code that demonstrates the above difference:

First run InDesign:

c:
cd "C:\Program Files\Adobe\Adobe InDesign CS6 Server x64"
InDesignServer.com -port 12345
pause

Next create a batch file to run a script:

c:
cd "C:\Program Files\Adobe\Adobe InDesign CS6 Server x64"
sampleclient -host localhost:12345 -server "C:/doscript_vs_evalfile/call_doScript.jsx"
pause

This is "call_doScript.jsx", which will call app.doScript.

try {
    app.doScript(new File("/c/doscript_vs_evalfile/called_by_doScript.jsx"));
    "Success";
}
catch (e) {
    var sError = "Encountered " + e.name + " #" + e.number + " at line " + e.line + " of file " + e.fileName + "\n" + e.message;
    app.consoleout(sError);
    sError;
}

This is "called_by_doScript.jsx", which is called by the previous script:

app.consoleout("Running called_by_doScript.jsx");
// Produce error
var a = b;

Run the batch file and this is the result:

02/25/13 13:30:03 INFO  [javascript] Executing File: C:\doscript_vs_evalfile\call_doScript.jsx
02/25/13 13:30:03 INFO  [javascript] Executing File: C:\doscript_vs_evalfile\called_by_doScript.jsx
02/25/13 13:30:03 INFO  [script] Running called_by_doScript.jsx
02/25/13 13:30:03 INFO  [script] Encountered ReferenceError #2 at line 2 of file /c/doscript_vs_evalfile/call_doScript.jsx
b is undefined

Notice that the error above is incorrect. The error was caused by line 3 of called_by_doScript, not line 2 of call_doScript.

Now modify the scripts to use $.evalFile, and we get this result:

02/25/13 13:32:39 INFO  [javascript] Executing File: C:\doscript_vs_evalfile\call_evalFile.jsx
02/25/13 13:32:39 INFO  [script] Running called_by_evalFile.jsx
02/25/13 13:32:39 INFO  [script] Encountered ReferenceError #2 at line 3 of file /c/doscript_vs_evalfile/called_by_evalFile.jsx
b is undefined

Notice that the error is now reported at the correct location.


Edit:

I found sparse documentation. It doesn't really answer my question, but it does describe different optional parameters.

doScript: Adobe InDesign CS6 Scripting Guide: JavaScript (direct link)
See page 16, "Using the doScript Method"

evalFile: Javascript Tools Guide: Adobe Creative Suite 5
See page 219

like image 259
dln385 Avatar asked Feb 25 '13 18:02

dln385


1 Answers

$.evalFile is an ExtendScript feature while app.doScript is implemented by InDesign.

$.evalFile does

  • maintain the $.stack
  • consider $.includePath
  • work in other target applications

app.doScript can

  • pass arguments
  • change the language, e.g. AppleScript
  • use #targetengine to address other sessions
  • modify the undo/transaction mode as far as supported

but ...

  • nested doScript calls overwrite arguments
  • in a complicated setup I had trouble to debug after passing more than 12 arguments.
  • single stepping across doScript is trouble

Also, as you found, error handling differs. Keep an eye on exceptions ...

like image 58
Dirk Avatar answered Nov 11 '22 02:11

Dirk