Writing a batch processing macro to run '3D Objects Counter' on a directory of .tif files

Hi, I’m a bit of an amateur when it comes to writing macros in ImageJ/Fiji.
I’d like to create a macro that runs ‘3D Objects Counter’ on a directory of .tiff files. I’d also like to apply a size filter
Min.: 10
Max: 207360.

Ideally, I would save the results, log, and objects map to separate folders.
Each of these three would be named…

  • original image name + “-results”.csv
  • original image name + “-log”.csv
  • original image name + “-objectsmap”.tiff

I have included the current version of my macro below.

/*
"BatchProcessFolders-Objects Counter"
This macro uses '3D Objects Counter' on a directory of .tiff files and saves the results table, log, and objects map to separate folders.
 /*
dir1 = getDirectory("/Volumes/USB-KH/2021.03.12-OSGC-5/T5/T5-NC-10E1");
dir2 = getDirectory("/Volumes/USB-KH/2021.03.12-OSGC-5/Max-proj");
list = getFileList(dir1);
setBatchMode(true);
for (i=0; i<list.length; i++) {
    showProgress(i+1, list.length);
    open(dir1+list[i]);
run(3D Objects Counter, "objects statistics summary");
// get original image title
Title = getTitle();
// save the results, log, and objects map
saveAs("Results", dir2+list[i] + "-Results.csv");
saveAs("Text", dir2+list[i] + "-Log.txt);
saveAs("Tiff", dir2+list[i] + "-objectsmap.Tiff);
close();
}