Copy link to clipboard
Copied
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.
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
Hi @Deleted User , 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_NUMB
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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"
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thank you this works too.
Copy link to clipboard
Copied
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';
}
Copy link to clipboard
Copied
Hi @Deleted User , 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:
Copy link to clipboard
Copied
Thank you. I had initially discarded include because it returns a syntax error, but it works.