How to tell a macro to make one window active

Dear all,
I have several images opened. Each of them with a different image title. How I can make one of them containing a specific word in its title the active window?

Is there something like this that works?:

selectWindow(containing the string in its title: “position 1”);

See:

selectWindow(“name”)
Activates the window with the title “name”.

From:
https://imagej.nih.gov/ij/developer/macro/functions.html#S

But I do not want to type the whole image name, only one of the words that appear on it.

Then use the string functions (e.g., contains) and iterate over all opened windows, see:

https://imagej.nih.gov/ij/developer/macro/functions.html#substring (and above)

http://imagej.1557.x6.nabble.com/Get-windows-titles-td3700495.html

Hi
@mvizoso
Please test this:[Here you have to enter two digits.i for pos and j for c=]

newImage ("Pos2 C=1", "8-bit ", 512, 512, 0); 
wait(1000);
newImage ("Pos3 C=0", "8-bit ", 512, 512, 0); 
wait(1000);
newImage ("Pos2 C=2", "black 8-bit ", 512, 512, 1); 
wait(1000);
newImage ("Pos2 C=3", "8-bit  ramp", 512, 512, 1); 
wait(1000);
newImage ("Pos1 C=3", "8-bit  ramp", 512, 512, 1); 
wait(1000);
// choose your window
//ForPos
i=3;
//ForC=
j=0;

selectActivWindow();


function  selectActivWindow()
{
selectWindow("Pos"+i+" C="+j);
wait(1000);
//setTool("polygon");
makePolygon(277,56,104,215,366,217);
}

Please, can you tell me about your results, if you don’t mind.

Another macro proposal.
Is this type of result you want?
Please can you tell me about your results, if you don’t mind.

newImage ("Pos2 C=1", "8-bit ", 512, 512, 0); 
wait(1000);
newImage ("Pos3 C=0", "8-bit ", 512, 512, 0); 
wait(1000);
newImage ("Pos2 C=2", "black 8-bit ", 512, 512, 0); 
wait(1000);
newImage ("Pos2 C=3", "8-bit  ramp", 512, 512, 0); 
wait(1000);
newImage ("Pos1 C=3", "8-bit  ramp", 512, 512, 0); 
wait(1000);
run("Tile");
// choose your window
  Dialog.create("Your imageName");
  Dialog.addChoice("i for Pos=", Array.getSequence(10));
  Dialog.addChoice("j for C=", newArray("0", "1", "2","3"));
  Dialog.show();
 i= d2s(Dialog.getChoice(),0);
 j=Dialog.getChoice();

selectActivWindow();


function  selectActivWindow()
{
selectWindow("Pos"+i+" C="+j);
wait(1000);
//setTool("polygon");
makePolygon(277,56,104,215,366,217);
}

I tried it but it did not work, thanks for helping.

Get the number of open images nImages(). Create a loop that loops over all images, select them by their number (the positive number P indicates the Pth window), getTitle() and see if the indexOf(title,yourword) is != -1. If that is the case, your word is in that title. And at that moment, the window has focus.
Alternatively, get all titles getList(“image.titles”) in an array, loop over the array and likewise check if indexOf myWindowTitles[i] and yourword is, or isn’t -1.

Give it a try and show us what you got.