Skip to main content
Inspiring
April 24, 2025
Answered

Can I pass arguments to #include script

  • April 24, 2025
  • 2 replies
  • 2546 views

I'll try to simplify this and add more detail if questions are asked:

I have two scripts: Script_A.jsx and Script_B.jsx.

 

Script_A.jsx creates a window and a button on the window runs:
#include "Script_B.jsx"

 

That works fine, but I would like to pass the window from Script_A to Script_B so Script_B can check some of the values from the window.

 

Is there a way to do this?

 

Something like:

#include "Script_B(win).jsx"

or

#include "Script_B.jsx {arguments:win}"

 

I realize it could be done by including the functions of Script_B into Script_A and making one massive script, but I'd like to make that my last resort.

 

Thanks in advance!

Correct answer Marshall_Brooks

Disregard, I just ran a test and if I call Script_B from Script_A using the include statement, all of the Scrpt_A variables and values are available to Script_B, so I don't need to pass it a variable.

2 replies

m1b
Community Expert
Community Expert
April 24, 2025

Hi @Marshall_Brooks you seem to be wanting to separate the UI (the window) from the script, which is an excellent idea. However, to do this, there are much easier ways than passing the window to a separate script file. One way that I commonly use is to handle the window creation and display (ie. the script's UI) in a function, and pass that function an object—I usually use a `settings` object containing all the properties the script needs.

 

You can see an example here. This post might be worth a bit of study because the OP's script has no separation of UI, and I post a version of the script which has the UI completely de-coupled, meaning that with a single "showUI = false" the script will run completely fine with no UI at all, using the properties already set in the `settings` object.

 

I also use #include files all the time—I store functions in the include file, and then call them from the main script. For a project I may have many many functions in such a "library" script file.

- Mark

Inspiring
April 24, 2025

Thanks! I had not heard of doScript before, and I'm not necessarily trying to separate the window from the script. Also I found this thread when I was researching DoScript: https://community.adobe.com/t5/indesign-discussions/how-do-i-make-a-script-both-executable-on-its-own-an-serve-as-a-library-for-other-scripts/td-p/13949570

 

Let me share more info on what I am trying to do!!

 

Script A and Script B were each originally developed independently.

 

Script A presents a window which has about 15 checkboxes. 10 of the checkboxes can be selected simultaneously and are common to checkboxes on Script B. (For discussion, lets call them Ford, Chevy, Honda, Mazda, Nissan).

 

Script B presents a different window (they both might be named win, which presents a problem). Script B's window presents other checkboxes, 10 of them are common to Script A (Ford, Chevy, Honda, Mazda, etc.), but only one can be selected at a time.

 

What I want to achieve is if the user has Chevy (and only Chevy) checked on Scirpt A and clicks the Script B button, which fires the #include statement to launch Script B, the Chevy checkbox is clicked when Script B opens.

 

Ways that I can see to achieve this - but there might be better solutions and I could be wrong - in order of what I understand:

 

  • I can modify Script B to change all references to win to win2 for similar and paste all of Script B's code into Script A. Then I can pass "win" from Script A to the functions of script b, check if Chevy is checked and only Chevy is checked, and if so, check Chevy on Script B's window.
  • If I understood the thread I linked above and @Manan Joshi's first comment, another approach would be to create a Script C and have it's first statement be #include "Script_A.jsx" Then the window of Script_A becomes a global variable and can be used by Script B. (I'm not seeing how this works - or if it does, maybe I'm overcomplicating things and the window from Script A is already avialable when I call Script B from the #include statement and I just have to modify Script B to take advantage of it.
  • If I understood @Manan Joshi second example with DoScript and my research on it, DoScript can pass a file, string, or javascript function as an argument, but not a variable like win from ScriptA. So I could use this, but I would have to add a function that checked if Chevy (Ford, Honda) was checked and only Chevy (Ford, Honda) was checked and returns a variable like CarType with value of "Chevy", "Ford", "Honda", or "" and then I can pass that in the DoScript argument to know which button to select on win2.

 

Marshall_BrooksAuthorCorrect answer
Inspiring
April 24, 2025

Disregard, I just ran a test and if I call Script_B from Script_A using the include statement, all of the Scrpt_A variables and values are available to Script_B, so I don't need to pass it a variable.

Community Expert
April 24, 2025

You could run both the scripts in the same engine, something like

#targetengine "main"

The you can set the variable you want to pass as a global variable and that will be available to script B.

 

Another approach could be to use the doScript method to call script B instead of #include. This method takes an array as an argument to pass to the calling script

-Manan

-Manan