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

Making ID execute background tasks before finishing a script

Community Beginner ,
Jul 28, 2020 Jul 28, 2020

Copy link to clipboard

Copied

Hi there!

If I have a script and I want InDesign to finish/execute triggered background tasks before continuing the rest of the functions, how do I do that?

I tried $.sleep(60000); and putting it in a 2nd script (which is called in script one), but ID always finishes the script first before (really) starting background tasks.

 

My specific case:

I have a script for importing an XML file into a threaded text frame, so multiple pages are automatically created from only one page & one master. Then, I want to "override all master page items", which works smoothly if I already have the other pages in my document.

BUT if I only have this one page (waaay cleaner/better to work with), the script first overrides the master page items, then adds all the (un-overridden) pages...

So with $.sleep(10000); I only have page 1 overridden, with $.sleep(30000) (ridiculously long for that task) it overwrites the first 4 (of ~60) pages... and the number doesn't go up with (60000)...

So that's a bit strange to me, that ID doesn't REALLY work on the tasks that are not started from directly within the script while the script is paused, but it DOES work on them for only like 4 pages... so maybe just until $.sleep pauses all of it!?

 

Is there a way to really split the script into two for ID without having to start two scripts manually?

Thanks! & all the best

Mathis

TOPICS
Scripting

Views

322

Translate

Translate

Report

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 1 Correct answer

Community Expert , Jul 28, 2020 Jul 28, 2020

Having a hard time visualizing without seeing the code, but have you tried calling document.recompose() after importing the XML, then calling the override method? Recompose should update the DOM info about the current document state without having to call sleep. 

 

The alternative would be to use app.doScript to call the second script when the time is right. But I don't think that would solve the problem. 

Votes

Translate

Translate
Community Expert ,
Jul 28, 2020 Jul 28, 2020

Copy link to clipboard

Copied

Having a hard time visualizing without seeing the code, but have you tried calling document.recompose() after importing the XML, then calling the override method? Recompose should update the DOM info about the current document state without having to call sleep. 

 

The alternative would be to use app.doScript to call the second script when the time is right. But I don't think that would solve the problem. 

Votes

Translate

Translate

Report

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 Beginner ,
Jul 28, 2020 Jul 28, 2020

Copy link to clipboard

Copied

LATEST

You're my hero 🙂 document.recompose() works like a charm! There's just nothing more to say 🙂

Thanks a lot to both of you!

Votes

Translate

Translate

Report

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 ,
Jul 28, 2020 Jul 28, 2020

Copy link to clipboard

Copied

Hi Mathias,

In my opinion we don't have access to delegate process to a background thread via scripting. The only api that does it as far as scripting is concerned is the pdf export. Js runs on a single thread so if you use sleep it will block the whole thread in totality. I have not played extensively around this, will see if someone more experienced chimes in with some interesting details.

 

-Manan

Votes

Translate

Translate

Report

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