Wait for macro execution until images are loaded

Dear helpers,

I’m running a macro code which should be executed after all images are loaded from a different software.
This macro is running from the Autostart.ijm.
Right now I’m using this line showMessageWithCancel("Text","Text"); and after all images are loaded (usually a stack of 200-300 slices) the user needs to click on “Ok” to execute the marco.
An other way would be to use the wait command set to an specific time.
But the macro is running from different PC’s and some are much slower and sometimes the dataset is bigger than the other so the waiting time would be different. And I want it to be the shortest possible time.

Is there a way to tell imagej that the macro should run until the stack is opened?
The name of the image stack is always the same (unfortunaly, but it might help in this case? :confused: )

Have you guy any ideas?

Thank you


Something like this might help:

while (!isOpen("myStackName")) {
// code below this line will only run once there is a "myStackName" image open
print("The stack was opened.");
1 Like

Dear Jan,

thank you very much! Again! :smile:
This is working.
But why did you use the wait(100); funktion?


The while loop gets repeated again and again as long as the condition resolves to true. By waiting 100 ms in each loop, I restrict the number of isOpen() requests to ten per second, which should be sufficient to still generate a user experience close to an “immediate response”.

Hi! How could this answer be implemented if I’m writing a python script to run in ImageJ?