Highlighted

Making ID execute background tasks before finishing a script

Community Beginner ,
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

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

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. 

TOPICS
Scripting

Views

54

Likes

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

Making ID execute background tasks before finishing a script

Community Beginner ,
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

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

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. 

TOPICS
Scripting

Views

55

Likes

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
Jul 28, 2020 0
Adobe Community Professional ,
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. 

Likes

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
Reply
Loading...
Jul 28, 2020 0
Mathisse LATEST
Community Beginner ,
Jul 28, 2020

Copy link to clipboard

Copied

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

Thanks a lot to both of you!

Likes

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
Reply
Loading...
Jul 28, 2020 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Jul 28, 2020 0