Skip to main content
Inspiring
July 30, 2020
Answered

Run a script from a script?

  • July 30, 2020
  • 1 reply
  • 2296 views

A while back I saw (i think i even made) a post about running a script from a script I have tried several search words and cannot find it. My question is can someone please Point me in the direction or just answer the question ( How do i run a script from another script? )

 

Thank you in advance.

This topic has been closed for replies.
Correct answer rob day

Hello,

What is the correct way to import functions into an InDesign script?

I grouped my functions into a separate .js file, imported with evalFile. Once the function is called, the script returns me an error: function_1 is not a function.

// main.js
var path = (new File ($.fileName)).parent + '/' + functions.js;
.evalFile (path);
function_1 (item);
// functions.js
function function_1 (a) {
    a.name = 'hello';
}

 


Hi @35626004 , You can use an #include directive to load a script and expose its functions. See this:

 

https://extendscript.docsforadobe.dev/extendscript-tools-features/preprocessor-directives.html

 

For example this script loads a script named HelloWorld.jsxinc (a .jsx extention should also work) which is saved in the same directory as the script:

 

#include "HelloWorld.jsxinc";

alert("Message from HelloWorld.jsinc:\r" + getWorldString("Hi There!") + "\rThe magic number is: "+ MAGIC_NUMBER)

 

The HelloWorld.jsxinc code:

 

/**
* External function example saved with .jsxinc in the same directory as script 
* @ param s string
* @ return new string 
*/

function getWorldString(s){
  return "From Hello World: " + s
}

/**
* A read only constant
*/
const MAGIC_NUMBER = 1.045;


/**
* A read write variable
*/
var vNum = 5

 

The example run result:

 

1 reply

Legend
July 30, 2020

Hello cbishop01

 

Check the link below to see if this what you're looking for.

https://stackoverflow.com/questions/4695444/adobe-indesign-jsx-script-execute-jsx-script

 

Regards,

Mike

cbishop01Author
Inspiring
July 30, 2020

Thanks for your reply. This would probably work however the one i was thinking of is simpler. I did find it after hours of searching I'll attach it below so anyone could use it if needed

 

app.doScript("/File/Location/Script.jsx"
SychevKA
Inspiring
July 31, 2020

hi, i use this code :

 

$.evalFile('/myscript.jsx')

 

perhaps this will be interesting:

https://community.adobe.com/t5/photoshop/evalfile-vs-include/td-p/3323884