Basic Macro Help ; expected in line but semi-colon present?

Hello!

I have learnt everything so far from these forums, and am hoping that someone smarter than I can help!
I am very new to scripting, and am trying to write a basic script that will run a basic threshold so I can analyse for areas size.
My goal is to make a bash for multiple processing among multiple images

Thank you so much in advance for your time, as it means very much to have help!!!

Questions:

  1. is it possible to change the file name when duplicated? I see the substring and indexof may be able to do this, I but I can’t find an example of what this script would look like
    hoping to know so that the analyse output will have the new name rather than "title-1.png’ under slice

  2. Here is my code, Currently getting " ; expected in line 26"
    Line 26 is " selectImage(total); "

// Open folder for processing
dir1 = getDirectory("Choose Source Directory ");
dir2 = getDirectory("Choose Destination Directory ");
list = getFileList(dir1);
setBatchMode(false);
for (i=0; i<list.length; i++) {
showProgress(i+1, list.length);
filename = dir1 + list[i];
if (endsWith(filename, “.jpg”)) {
open(filename);
{
///duplicate single image for 3 way processing
total = getImageID();
print(total);
run(“Duplicate…”, " ");
stroke = getImageID();
print(stroke);
selectImage(stroke);
run(“Duplicate…”, " ");
nonstroke = getImageID();
print(nonstroke)

//Total volume
selectImage(total);
print(getTitle());
run(“Scale to DPI”, “dpi=600 width=0.163 height=0.122 interpolation=Bilinear average create”);
run(“Color Threshold…”);
// Color Thresholder total
min=newArray(3);
max=newArray(3);
filter=newArray(3);
a=getTitle();
run(“HSB Stack”);
run(“Convert Stack to Images”);
selectWindow(“Hue”);
rename(“0”);
selectWindow(“Saturation”);
rename(“1”);
selectWindow(“Brightness”);
rename(“2”);
min[0]=0;
max[0]=255;
filter[0]=“pass”;
min[1]=0;
max[1]=255;
filter[1]=“pass”;
min[2]=122;
max[2]=255;
filter[2]=“pass”;
for (i=0;i<3;i++){
selectWindow(""+i);
setThreshold(min[i], max[i]);
run(“Convert to Mask”);
if (filter[i]==“stop”) run(“Invert”);
}
imageCalculator(“AND create”, “0”,“1”);
imageCalculator(“AND create”, “Result of 0”,“2”);
for (i=0;i<3;i++){
selectWindow(""+i);
close();
}
selectWindow(“Result of 0”);
close();
selectWindow(“Result of Result of 0”);
rename(a);
// Colour Thresholding-------------
run(“Analyze Particles…”, “display clear summarize”);
saveAs(“JPG”, dir2+list[i]);

	//Stroke volume
	selectImage(stroke);
	print(getTitle());
	run("Scale to DPI", "dpi=600 width=0.163 height=0.122 interpolation=Bilinear average create");
	run("Color Threshold...");
		// Color Thresholder stroke
			min=newArray(3);
			max=newArray(3);
			filter=newArray(3);
			a=getTitle();
			run("HSB Stack");
			run("Convert Stack to Images");
			selectWindow("Hue");
			rename("0");
			selectWindow("Saturation");
			rename("1");
			selectWindow("Brightness");
			rename("2");
			min[0]=0;
			max[0]=255;
			filter[0]="pass";
			min[1]=0;
			max[1]=84;
			filter[1]="pass";
			min[2]=214;
			max[2]=255;
			filter[2]="pass";
			for (i=0;i<3;i++){
			  selectWindow(""+i);
			  setThreshold(min[i], max[i]);
			  run("Convert to Mask");
			  if (filter[i]=="stop")  run("Invert");
			}
			imageCalculator("AND create", "0","1");
			imageCalculator("AND create", "Result of 0","2");
			for (i=0;i<3;i++){
			  selectWindow(""+i);
			  close();
			}
			selectWindow("Result of 0");
			close();
			selectWindow("Result of Result of 0");
			rename(a);
		// Colour Thresholding-------------
	run("Analyze Particles...", "display clear summarize");
	saveAs("JPG", dir2+list[i]);
	

	//non-stroke volume
	selectImage(nonstroke);
	print(getTitle());
	run("Scale to DPI", "dpi=600 width=0.163 height=0.122 interpolation=Bilinear average create");
	run("Color Threshold...");
	// Color Thresholder non-stroke
		min=newArray(3);
		max=newArray(3);
		filter=newArray(3);
		a=getTitle();
		run("HSB Stack");
		run("Convert Stack to Images");
		selectWindow("Hue");
		rename("0");
		selectWindow("Saturation");
		rename("1");
		selectWindow("Brightness");
		rename("2");
		min[0]=0;
		max[0]=255;
		filter[0]="pass";
		min[1]=50;
		max[1]=255;
		filter[1]="pass";
		min[2]=185;
		max[2]=255;
		filter[2]="pass";
		for (i=0;i<3;i++){
		  selectWindow(""+i);
		  setThreshold(min[i], max[i]);
		  run("Convert to Mask");
		  if (filter[i]=="stop")  run("Invert");
		}
		imageCalculator("AND create", "0","1");
		imageCalculator("AND create", "Result of 0","2");
		for (i=0;i<3;i++){
		  selectWindow(""+i);
		  close();
		}
		selectWindow("Result of 0");
		close();
		selectWindow("Result of Result of 0");
		rename(a);
		// Colour Thresholding-------------
	run("Analyze Particles...", "display clear summarize");
	saveAs("JPG", dir2+list[i]);

}

}
}

Good day Kathleen Harrison,

with respect to

Here is my code, Currently getting " ; expected in line 26"
Line 26 is " selectImage(total); "

I can help you further:

If you receive such a warning it is always a good idea to look at the code line above (comments don’t count). That said it is the code line

print(nonstroke)

that is missing the semicolon.

Concerning the other issue, please have a look at the many examples of ImageJ macro code available at:
https://imagej.nih.gov/ij/macros/examples/

HTH

Herbie