Edit in GitHubLog an issue

Setting Script Result

Since InDesign v18.4, you can "set result" of a UXP script.

After execution, a script can return a result, which could be used for evaluating the outcome of script execution. The result can be set using script.setResult() API as shown below.

Setting the result

The following line sets the result of the UXP script being executed to the string "Hello World!".

Copied to your clipboard
// called.idjs
const script = require("uxp").script;
script.setResult("Hello World!");

Reading the script result

The below code snippets demonstrate how to read the script result of another script.

Copied to your clipboard
// caller.idjs
const myInDesign = require("indesign");
const app = myInDesign.app;
const resultOfCalledScript = app.doScript("PATH_TO_CALLED.IDJS/called.idjs", myInDesign.ScriptLanguage.UXPSCRIPT);
console.log(resultOfCalledScript);

Scripts can return a result by setting the appropriate value using setResult() API. This result is returned to the entity that invoked this script. If this script was executed from InDesign's scripts panel, then the result is ignored. However, for scripts executed in InDesign Server, the result value is returned to the client that requested the script execution. If the script is forked by another script using app.doScript() API the result value set by 'called' script is returned to the 'caller' script, as illustrated above.

The result after executing this script on InDesign Server is shown on the client side. 

Copied to your clipboard
Script result (std__string): Hello World!
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.