Skip to main content
Inspiring
May 8, 2025
Question

Timing Issues with Scripts

  • May 8, 2025
  • 3 replies
  • 965 views

@frameexpert - Adding a mention since you don't necessarily follow the InDesign boards.

 

First off, I know this isn't only an Adobe issue. I've run into similar problems with Visual Basic (and similar solutions).

 

Anyway - My scripts tend to run through a lot of steps and function calls. I've noticed that sometimes some of the steps are "missed" - i.e., I'll run the script and the expected action does not happen. I'll run the script again and it works as expected. I'm "assuming" that the script moves on to the next action before the previous one completes and that causes the issue.

 

I've found often putting a 0.5-second pause before and after the action usually resolves the issue:

$.sleep(500);

but I wasn't sure if this was commonplace (I haven't seen it often in scripts others posted online), or if there was a better solution ...

 

Issues with this solution (applies to VBA also):

 

  • Since the script works (sometimes) without the sleep statements, it's hard to know if they are required. It's only a 0.5 second pause, but if I have to add 40 of them, I've added 20 seconds to a script that might have run fine with only 2 seconds added.

 

  • Similarly, since the script works (sometimes) without the sleep statements, it's hard to know when the pause time is sufficient - i.e. if the script failed 50% of the time with no delay statements, did the 0.5-second delay fix it, or did it just mean that in only fails 10% of the time, but not the time that I tested and it needs to be 1-second or 2-seconds. And if I set it to 5-seconds to be sure it waits long enough, I'm back to added extra unnecessary delay to the script.

 

Thanks in advance!

3 replies

Community Expert
May 13, 2025

Hi @Marshall_Brooks ,

with very large InDesign documents I would work with exportFile() instead of asynchronousExportFile().

You could determine this e.g. by the number of pages that are involved in the export process.

 

Notes:

Perhaps it would also help if your script has only one document open at the same time going through a lot of documents in a folder or documents from a book file.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

m1b
Community Expert
Community Expert
May 9, 2025

Hi @Marshall_Brooks a pause might help when you are dealing with an asynchronous call to some other process, but it is not a comfortable situation. Can you identify the "actions" that might be causing the subsequent missing operations? Sometimes there are more robust approaches that avoid them without hacks like $.sleep.

 

Putting a delay *before* an operation suggests that it is actually *after* a previous operation that has not completed. Otherwise there is no reason to sleep before an operation because nothing has happened yet.

 

Perhaps you could insert an assertion into the code after the "action" that checks if the action is finished (this could be a while loop with a short $.sleep(100) and a timeout. Just an idea.

- Mark

Inspiring
May 12, 2025

Great suggestions. The script does multiple things. The specific action that was being skipped was a find and replace character formats. The action before that step was a save document (to a network drive). The action before that were other find and replace text statements. The script also sets and hides conditional formats, opens a template on the network drive and updates master pages, etc.

 

Also, there seem to be two types of intermittent errors:

  • Sometimes the script seems to run fine, but it just "skips over" a step like the find/replace above. Sleep statements seem to fix that. Not the most elegant way to handle it.
  • The script opens a pop-up window that stays open and allows you to click buttons to run other actions. Sometimes the scripts seems to freeze - i.e. I thought it was skipping on of the conditional format apply actions, but I tried to do something else and that did not work either. Closing the pop-up window and re-running the script, it worked again.

 

Robert at ID-Tasker
Legend
May 13, 2025

@Marshall_Brooks

 

I don't think F&C is asynchronous?

 

Unless, your scripts are UXP scripts? 

 

Robert at ID-Tasker
Legend
May 8, 2025

What kind of operations are you talking about? 

 

I know at least one specific situation - but maybe it's not the same.