Skip to main content
Participating Frequently
June 7, 2023
Answered

InDesign script executing after dialog.show()

  • June 7, 2023
  • 3 replies
  • 1516 views

Hi,

 

Is there a way to continue the execution of the script after showing the dialog window, without user interaction?

I'm working on a script that uses the .findGrep() function. With long documents it could take some time. I would like the user to know that the script is working and is not hang. But as the findGrep() is a single line, I cannot use the progress bar. I thought I show the dialog, with some statictext like "processing..." then change the text when the find command is done. But after the show() command, the dialog is waiting for interaction. I tried onShow, but it is called before the window is made visible, so it's not working for me.

 

This topic has been closed for replies.
Correct answer Peter Kahrel

A dialog-type window waits for you to click OK, then the script can continue. It's like InDesign doalog windows: while they're visible you can't do anything else.

 

What you need is a paletter-style window. They are like InDesign panels: while they're visible you can work on you document, and a script can do stuff while the paletter is displayed.

 

P.

3 replies

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
June 11, 2023

A dialog-type window waits for you to click OK, then the script can continue. It's like InDesign doalog windows: while they're visible you can't do anything else.

 

What you need is a paletter-style window. They are like InDesign panels: while they're visible you can work on you document, and a script can do stuff while the paletter is displayed.

 

P.

JakabZsAuthor
Participating Frequently
June 12, 2023

Hi Peter,

 

Thank you very much. Indeed this is what I need! 🙂

I'll give try to the palette.

 

Thanks again

Zsolt

Robert at ID-Tasker
Legend
June 8, 2023
JakabZsAuthor
Participating Frequently
June 9, 2023

Hi Robert,

 

Thank you for your reply, but that's not the problem. I know how to make a progressbar, but if you have olny one line (i.e. findGrep() ), you cannot show the progress.

Robert at ID-Tasker
Legend
June 9, 2023

I'm not JS guy - but can't you use "progressbar way" anyway?

 

Show 50% as an indicator that there is something going on - and then when it finished - jump to 100% and "finished"?

 

Charu Rajput
Community Expert
Community Expert
June 8, 2023

Hi,

Could you please post your existing code?

Best regards
JakabZsAuthor
Participating Frequently
June 9, 2023

Hi Charu,

Thank you for your reply, but my problem is that I do not really have an existing code - because I do not know, how to do it.

I have defined a new Window:

w = new Window("dialog");

 

with some static tex:

t = w.add("statictext", undefined, "Processing...");

 

then I show the dialog:

w.show();

 

And at this point I want to execute the

found = app.selection[0].findGrep();

 

command, and then, when it finishes, change the text:

t.text = found;

 

But the onShow would execute anything before actually showing the window, and after w.show(); the execution stops, and is waiting for any user interaction. My question is: is there a way around it?

 

Zsolt

 

 

rob day
Community Expert
Community Expert
June 11, 2023

I do not really have an existing code - because I do not know, how to do it.

 

Hi @JakabZs , The findGrep() method returns a single array of results—I don’t think you would need a progress bar, but if you wanted to loop thru a very long array, the progress increment could be add to the for loop.

 

Here my found variable is the result array:

 

 

 

 


//would gets every Foo
 var found = getGrepSearch("Foo")
 alert(found.length)
 //returns the length of the search array

for (var i = 0; i < found.length; i++){
    $.writeln(found[i])
    //returns each item of the array e.g. [object Word]
};   


/**
* Gets results of a grep search 
* @ param text to search for 
* @ return search results as an array 
*/
function getGrepSearch(fp){
    app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
    app.findGrepPreferences.findWhat = fp;
    //an array of search results
    return app.activeDocument.findGrep()
}

 

 

 

 

 

 

 

If I wanted to change each array item, I could use the changeGrepPreferences changeTo property. This should be much faster than looping through the found array:

 

 

 

 

/**
* Document Grep find and change 
* @ param f the find grep string 
* @ param c the change grep string
* @ return void 
*/
function grepSearch(f,c){
    app.findGrepPreferences = app.changeGrepPreferences = app.findChangeGrepOptions = null;
    app.findGrepPreferences.findWhat = f;
    app.changeGrepPreferences.changeTo = c;
    app.activeDocument.changeGrep( true )
}

 

 

 

 

 

Here the 128 changes happen instantly