What's the ImageJ script for clicking a button on a plugin?

What’s the ImageJ script for clicking a button on a plugin’s GUI window?

I’m trying to write an automated macro to analyze IHC images using IHC Tool Box. I need to click the button “Read User Model” to select my own defined model that I have, then click “Color” to execute the analysis. I can write the loop to go through all images in the directory and save the results. But I cannot figure out how to write the script to click these buttons, or any buttons in general.

My best guess is it’ll be something along the line of:

run("IHC Toolbox", "some option to click wanted button here

But because Macro Recorder doesn’t seem to record my clicking act, I don’t know what this argument should be.

Welcome to the forum @puifais.

Have a look at IJ_Robot by @gabriel, distributed with FIJI. It was designed for that exact purpose. Good luck!

Hi @tferr,

Wow, this is so close and yet so far! Thank you for letting me know about this. Do you, or @gabriel, have any example scripts so that I can modify and run it? (Sorry, brand new with both ImageJ and Java here…) In particular, something along the line of clicking the tab key a few times, followed by the enter key using the KeyPress command from the IJ Robot plugin?

Here is an example that clicks repeated times (once every 1.5 sec) on the screen pixel 159,62, (for 300 ms) where a grabbing program has the button to grab images, until 8 images have been acquired.

while (nImages<8){
  showStatus("Capturing image "+ (nImages+1) ) ;
  run("IJ Robot", "order=Left_Click x_point=159 y_point=62 delay=300");

The IJ Robot does not know where it is clicking other than the screen (not window) coordinates. So if I were to move the grabbing program elsewhere on the screen, it would be clicking on the screen forever (as there are never 8 images grabbed.
You have to know where on the screen a window might exist and the action is to be performed. This is tricky, so you might have to locate windows in very precise locations for the clicking to be correct.
Be careful how you use the robot, it is very easy to get locked into loops that do not do anything by click a screen place. If you find a way of knowing which external program or window one is clicking on, please let me know, as it would resolve all sorts of problems.

Thank you! Do you also have some examples for KeyPress of space bar, tab, or enter? I think the x,y,z coordinate would be okay but it would not work between computers (i.e. could not share the macro with multiple users). But the keyboard inputs will work with many computers.

Please have a look in the following page for the IJ Robot information:

1 Like