(CS5 Mac) -- this is strange -- I got 2 main results:
1. If I run from ESTK instead of the Scripts Panel, no crash.
2. Perhaps more usefully, if you change the name of your global variable from "globalVar" to "g_globalVar", no crash.
Tentative conclusion: "globalVar" might be some kind of hidden "reserved" name in global space, used for some other purpose by ExtendScript.
These days, I usually put my functions and 'global' variables in a separate namespace object, to avoid any possible name conflicts.
As far as I have experienced this bug appeared in ID CS5 and is not solved yet. It is not related to the use of a startup script, a persistent engine, app.docript(), etc., and it has no connection with global variables, variable names, etc.
The bug typically occurs when:
1) A script inserts a label into the active document;
2) Once the script has finished, the user attempts to close the active document and does not save it.
Minimal code that should lead to the bug:
// then the user go to File > Close
My own speculation about the causes of this bug:
The internal pointer which holds app.activeDocument is not properly updated after insertLabel() is done. Maybe at some level the subsystem does not identify the label insertion as an actual modification and forgets to refresh some underlying specifier... Who knows?
I found that just accessing the property app.activeDocument at the end of the script usually fixes the instability, as this probably causes the system to recalculate the document specifier:
app.activeDocument; // patch
// => no bug
As a stronger and safer approach, I suggest you add this line at the end of any script:
app.properties.activeDocument && app.activeDocument.getElements();
Of course this is all without warranty!
Hope that helps.
InDesign CS5 v22.214.171.1243 (German)
InDesign CS5.5 v126.96.36.1993 (German)
Mac OSX 10.6.8 (German)
@bduffy – I experience a crash when using your set of scripts in InDesign CS5 (without using the ESTK).
After a restart of the crashed InDesign app the changed file will be opened again (the usual repair mechanism of InDesign kicks in) and then could be closed without saving. No crash at this point.
No problems running "globalTest.jsx" out of the ESTK and closing the file without saving.
@stephen0218 – changing "globalVar" to "g_globalVar" in my case did not prevent the crash!
@Marc – just tested your line of code on my German InDesign CS5.5. I tested with the ESTK and InDesign, only.
1. Closing the file with cmd + w
2. Using its menu equivalent
3. Closing by ticking the x in front of the file name
No crash occured if choosing to close the file without saving.
I have some start-up scripts running not related to bduffy's script.
To see if they prevent InDesign from crashing I removed them and rerun the tests.
Same result. No crash…
Also: no problems with your line of code in InDesign CS5.
Message was edited by: Laubender
Message was edited by: Laubender
> I tested with the ESTK and InDesign, only.
With ESTK all is fine to me too. (Note: ESTK has its own workspace, document manager etc, so it surely interacts with InDesign's active document.)
I suggest you make the test without ESTK.
Thank you everyone for your time to recreate this error! Marc's tentative solution seems to do the trick so I will go in and add this to my scripts. Is this something that I should submit as a bug to adobe or is it known bug on their end as well?
@Marc – I got no error with your line of code…
With or without using the ESTK.