Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Run a script from a script?

Advisor ,
Jul 30, 2020 Jul 30, 2020

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.

TOPICS
Scripting
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Participant , Jul 30, 2020 Jul 30, 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

Translate
Community Expert , Mar 10, 2024 Mar 10, 2024

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
...
Translate
Advisor ,
Jul 30, 2020 Jul 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 30, 2020 Jul 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"
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 30, 2020 Jul 30, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 31, 2020 Jul 31, 2020

Thank you this works too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 10, 2024 Mar 10, 2024

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';
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 10, 2024 Mar 10, 2024

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:

 

Screen Shot 31.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 11, 2024 Mar 11, 2024
LATEST

Thank you. I had initially discarded include because it returns a syntax error, but it works.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines