Timing Issues with Scripts
@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!
