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

Run a script from a script?

Advocate ,
Jul 30, 2020 Jul 30, 2020

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.

TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

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

Votes

Translate

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

Hi @Ralph S. , 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)

...

Votes

Translate

Translate
Advisor ,
Jul 30, 2020 Jul 30, 2020

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

Votes

Translate

Translate

Report

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

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"

Votes

Translate

Translate

Report

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

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

Votes

Translate

Translate

Report

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
Advocate ,
Jul 31, 2020 Jul 31, 2020

Copy link to clipboard

Copied

Thank you this works too.

Votes

Translate

Translate

Report

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 Beginner ,
Mar 10, 2024 Mar 10, 2024

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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi @Ralph S. , 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

Votes

Translate

Translate

Report

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 Beginner ,
Mar 11, 2024 Mar 11, 2024

Copy link to clipboard

Copied

LATEST

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

 

Votes

Translate

Translate

Report

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