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

1

10

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

Ironing answered 25/2, 2013 at 18:51 Comment(1)
I don't know the answer, but I would venture that with app.doscript, you can run js files as well as vbs files.Helicograph
M
9

$.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 ...

Meiosis answered 26/2, 2013 at 19:49 Comment(2)
Can anyone of these be used to access a js-file remotely on a web-server? i.e. 'mywebsite/script.js'?Each
@CarlPapworth You can use app.doScript to execute an AppleScript to run a do shell script to execute a curl command. You'll have to ensure quotes are escaped properly but it does work. Sadly, this is the only way I've found to do this in ExtendScript.Astrict

© 2022 - 2024 — McMap. All rights reserved.