Coloc2 Macro - Automatically Save PDF

Hello!

I am trying to write a Macro that will perform Coloc2 on many different TIFFs in a folder.
The idea is to define 3 ROI’s for each picture before I run the program --> The 1st ROI is a Background ROI to calculate the Mean with MultiMeasure on all 3 channels, then the Macro subtracts it.
In the last step I run the Coloc2 Plugin with the second and third ROI on each channel combination. Here is the Macro:

run("ROI Manager...");
open("Filepath/Filename");
roiManager("Open", "Filepath/Filename");

//select "Background" ROI for Mean-Measurements
roiManager("Select", 0);
roiManager("Multi Measure");
selectWindow("Results");
mean1 = getResult("Mean", 0);
mean2 = getResult("Mean", 1);
mean3 = getResult("Mean", 2);

//subtract the Means of each channel
run("Stack to Images");
//subtract ch1
selectWindow("tile_x001_y001-0001");
run("Subtract...", "value=" + mean1);
//subtract ch2
selectWindow("tile_x001_y001-0002");
run("Subtract...", "value=" + mean2);
//subtract ch3
selectWindow("tile_x001_y001-0003");
run("Subtract...", "value=" + mean3);

//select the actual ROI's and run Coloc2 on each channel combination
roiManager("Select", newArray(1,2));
run("Coloc 2", "channel_1=tile_x001_y001-0001 channel_2=tile_x001_y001-0002 roi_or_mask=[ROI Manager] threshold_regression=Costes show_save_pdf_dialog display_images_in_result manders'_correlation 2d_intensity_histogram psf=3 costes_randomisations=10");
//Analyses Channel 1 vs Channel 2
//Space for SaveFile Code
run("Coloc 2", "channel_1=tile_x001_y001-0001 channel_2=tile_x001_y001-0003 roi_or_mask=[ROI Manager] threshold_regression=Costes show_save_pdf_dialog display_images_in_result manders'_correlation 2d_intensity_histogram psf=3 costes_randomisations=10");
//Analyses Channel 1 vs Channel 3
//Space for SaveFile Code
run("Coloc 2", "channel_1=tile_x001_y001-0002 channel_2=tile_x001_y001-0003 roi_or_mask=[ROI Manager] threshold_regression=Costes show_save_pdf_dialog display_images_in_result manders'_correlation 2d_intensity_histogram psf=3 costes_randomisations=10");
//Analyses Channel 2 vs Channel 3
//Space for SaveFile Code

My question now is:
Is it possible to write a Macro that will let me automatically save the PDF that pops up after each Coloc2 Analysis ends in a specific folder?

I should note that my Macro currently uses specific file names. The final Macro will use generalised names so that it works on all files.

Thanks in advance!

Hi I wrote a code to do pairwise comparison of images in a folder with coloc2.
I am able to use ROIs too. Maybe you can adapt it slightly so that it serves your purpose.
To save the results I save the log window and excel to extract the needed data. It is the most straightforward solution that I found:

//This macro will do a pairwise colocalisation analysis with all images in the chosen directory
//To save the results do right click on the "log" file and click "save as"
//Important: all other images need to be closed when you start the script
//For ROI load the desired ROI in the ROI-Mangager (first entry) and replace run("Coloc 2"... by -> roiManager("Select", 0); run("Coloc 2", "channel_1=file1 channel_2=file2 roi_or_mask=[ROI(s) in channel 2] threshold_regression=Bisection li_icq spearman's_rank_correlation costes'_significance_test psf=5 costes_randomisations=10");
//For noROI replace -> roiManager("Select", 0); run("Coloc 2"... by -> run("Coloc 2", "channel_1=file1 channel_2=file2 roi_or_mask=<None> threshold_regression=Bisection li_icq spearman's_rank_correlation costes'_significance_test psf=5 costes_randomisations=10");

path = getDirectory("Choose directory");
list = getFileList(path);
for (i=0; i<list.length; i++) {
	file1 = path + list[i];
	open(file1);
	for (j=i+1; j<list.length; j++) {
		file2 = path + list[j];
		open(file2);
		run("Coloc 2", "channel_1=file1 channel_2=file2 roi_or_mask=<None> threshold_regression=Bisection li_icq spearman's_rank_correlation costes'_significance_test psf=5 costes_randomisations=10");
		close();
	}
	close();
}