Skip to main content
Inspiring
August 3, 2026
Question

#include causes UI to immediately close?

  • August 3, 2026
  • 1 reply
  • 24 views

I’ve been writing scripts for many years and I have created a large library of helper “include” scripts that I share between scripts, but they have never worked when I need a UI Window. Is this a known behavior?

I just went through a long trouble shooting session with AI and tested all kinds of configurations and here is what I know

the included files run and there are no errors - I can verify defined variables and functions when I run the script, but any UI fails to load

the UI shows if instead of #include, I eval() the file

the UI shows if I interrupt the script with an alert() window and the UI will remain visible till I dismiss the alert

I’ve tested it with stripped down scripts with no logic just the UI. stripped down include files, even empty ones, the conclusion is the same. #include causes windows to not show, or close immediately. i have “#target illustrator; #targetengine main” at top. etc.

Is this the expected behavior?

1 reply

m1b
Community Expert
Community Expert
September 2, 2026

Hi ​@mecdos it may be just an architectural problem. I use ScripUI and many includes regularly without problems. Are you able to share your stripped down script so I can look at your architecture?

In the meantime, I’d recommend the following guideline for the included files: that don’t do anything except define Functions or ExtendScript objects. Quick test: can you run an included file directly as a script and (a) nothing happens and (b) no error is thrown? That is what you want. After including, can you see the object(s) in scope? If not, then check if your included file is making them, or if there is a silent error due to try/catch.

It’s fine to load the UI function(s) in the included file, but you should be executing via your main entry script (the one that #includes the others). Note that the UI execution doesn’t have to be in the entry script, but it should have the entry script context as an ancestor. Don’t put execution in the included file(s), not because you can’t make it work that way, but because it’s messy and hard to troubleshoot.

Anyway I’d be happy to look at your architecture and test on my machine and see if I can suggest any improvements.

– Mark