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

Can I pass arguments to #include script

Enthusiast ,
Apr 24, 2025 Apr 24, 2025

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!

TOPICS
Scripting
2.1K
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

Community Expert , Apr 24, 2025 Apr 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

Translate
Enthusiast , Apr 24, 2025 Apr 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.

Translate
Enthusiast ,
Jun 25, 2025 Jun 25, 2025

@m1b ...

I'm making progress ...

I decided to get rid of the include statements and put everthing in one massive script.

I have to do some debugging (it isn't working properly yet), but it isn't giving me a stack overrun.

 

Where do I find the debugger? I'm using ExtendScript Toolkit and I see Debug with options like Step Into, and Toggle Breakpoint, but nothing like you show above.

 

Other comments:

  • I probably can get away with only putting the major scripts into the master script and still using include statements for the minor scripts.
  • The stackoverrun has something to do with #Include statements. The script called back to the main script, which could call back to the calling script, but only through the correct switch or If blocks. It shouldn't create an infinite loop.
  • As I've said previously, a lot of the issue is that I'm am coming from a Visual Basic Applications background where the compiler will give me "Duplicate Declarations in the current scope" and "Ambiguous Subroutine Name" errors - whereas it seems like Javascript USUALLY doesn't care.
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 ,
Jun 25, 2025 Jun 25, 2025

Hi @Marshall_Brooks that's not a bad idea starting with a long script and you can refactor the library functions out later as it starts to make more sense.

 

I'm using VSCode and the ExtendScript Debugger extension. My launch.json for general scripting in Indesign looks like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "extendscript-debug",
            "request": "attach",
            "name": "Indesign—-main",
            "hostAppSpecifier": "indesign",
            "engineName": "main",
        }
    ]
}

 

Again, I suggest you use the includes for library functions, not immediate code. In other words, load it, and call it when you need it; the library scripts should do nothing when they are evaluated except instantiate functions and objects. Just my opinion, but I keep harping because it would solve the problems you discuss in this thread.

 

If you've never set up a project in VSCode it can be a bit of work, but well worth it. Also in VSCode with ExtendScript Debugger, instead of #include, use //@include. They do the same thing but the latter won't trigger your linter.

 

And yes, javascript will let you get away with crazy stuff, with few guardrails! TypeScript this aint.

- Mark

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
Enthusiast ,
Jun 25, 2025 Jun 25, 2025

What does VSCode gain me? - or more specifically, I have a lot of common functions, such as AutoCloseAlert, which were part of each script. Is there some program that would say "Ambigous Name Detected" and help me delete the duplicates. Javascript doesn't care, but it's 40 or 50 lines of code repeated 8 or 10 times for no benefit.

 

Update: https://support.google.com/docs/thread/290701903/how-do-i-find-duplicate-functions-in-a-project?hl=e... - From other searches, it looks like duplicate function names won't typically be detected b/c Javascript doesn't care - i.e. it doesn't consider it an error. It looks like I could write a script to check for duplicates, but I don't know how to do that.

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
Enthusiast ,
Jun 25, 2025 Jun 25, 2025

I installed VSCode, but when I installed the ExtendScript Debugger, it says "This extension has been disabled because the current workspace is not trusted."

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 ,
Jun 25, 2025 Jun 25, 2025

>  it says "This extension has been disabled because the current workspace is not trusted."

 

That VSCode's deliberate behavior. See this article. It is easy to fix.

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 ,
Jun 25, 2025 Jun 25, 2025

> What does VSCode gain me?

Aside from a much better debugger? It's a million times better IDE. Objectively. 🙂

 

As for the common functions.. just put them in a library file, one after the other. Don't call them in the library file, just define them. And include that file. Call it "Functions.js" or :"Helper.js" or something. As you go throught your code, strip out those common function definitions into your helper library file. If you have many functions, feel free to make multiple library files, with different groupings of functions. But again, make sure they don't do anything on their own—you should be able to run them without error, or effect.

- Mark

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
Enthusiast ,
Jun 25, 2025 Jun 25, 2025

I'm going to hold off on VSCode for now. I think it looks valuable, but the learning curve is rather steep right now.

 

I still want to find a way to parse the script and find duplicate function names. I found https://stackoverflow.com/questions/11279441/return-all-of-the-functions-that-are-defined-in-a-javas... and came up with:

for(var i in this) {
	if((typeof this[i]).toString()=="function"&&this[i].toString().indexOf("native")==-1){
		$.writeln('<li>'+this[i].name+"</li>")
	}
}

It seems to write all the function names from all the tabs that are open in ESTK, but it doesn't find duplicates - i.e. I know that set_font appears multiple times, but it only shows up once (probably b/c Javascript only considers the last instance of it).

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 ,
Jun 25, 2025 Jun 25, 2025

The 'functions' window of the ESTK does show duplicate function names. But only of the active script window. You could just plonk everything in a single file and hunt down the duplicates there.

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
Enthusiast ,
Jun 25, 2025 Jun 25, 2025
LATEST

@Peter Kahrel - Awesome - that's what I was looking for and only for the active window. I can work with this! Thanks again!

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