Using macro to open .lif/.tif files

Hi,

I am experienced java developer, but I am new to fiji. Trying to help out scientists friend to automate his image processing.

I am trying to open .lif/.tif files, which contains multiple images in “stack”. Once files are opened, I can change slices and do most of actions I’d want.
Problem is opening itself. When I open file using “open” command (or manually), “Bio-Formats Import Options” window shows up. I don’t know how to confirm that window (I just need to press “OK” or hit “enter”). Then another window “Bio-Formats Series Options” appears, where I need to press “Select All” and “OK”.

I couldn’t find a way. I biggest problem is, that when those windows are opened, script is blocked until they are closed so lines after “open” are not executed until those windows are resolved and closed. How would you proceed?

I probably could create plugin, that will run something on background so that it doesn’t get blocked, wait for image with that title, find button with text in there and click on it, but that sounds quite complicated and a bit of overkill.
Is it normal, that some windows block macro execution and make it almost impossible for macro to control them?

Any general comments, that explain this behaviour is welcomed as I am very new to fiji ecosystem. I don’t mind making some good generic tool for usecases like this with some guidance.

K

I’ve found, that there’s Windowless_Importer and macro extensions, that allow opening file through that windowless importer and do what I wanted to do quite simply:

Dear @fijikh,

you can use the following macro and adapt it regarding your import options for your series. Tthis is easiest done by once recording one image import and then changing it accordingly in the macro.
At the labelled part you can put your macro code for processing. With some small changes this should actually work for all types of Bio-Format readable files in a specified folder (and all subfolders).

run("Bio-Formats Macro Extensions");

userChosenDirectory = getDirectory("Choose a Directory");

processBioFormatFiles(userChosenDirectory);

function processBioFormatFiles(currentDirectory) {

	fileList = getFileList(currentDirectory);

	for (file = 0; file < fileList.length; file++) {
		Ext.isThisType(currentDirectory + fileList[file], supportedFileFormat);
		if (supportedFileFormat=="true") {
			Ext.setId(currentDirectory + fileList[file]);
			Ext.getSeriesCount(seriesCount);
			for (series = 1; series <= seriesCount; series++) {
				//record the Bio-Formats importer with the setup you need if different from below and change accordingly
				run("Bio-Formats Importer", "open=[" + currentDirectory + fileList[file] + "] autoscale color_mode=Composite rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT series_"+series);
				//add your macro code here
			}
		} else if (endsWith(fileList[file], "/")) {
			processBioFormatFiles(currentDirectory + fileList[file]);
		}
	}
}

Thanks, that can be useful if I need to change parameters of import when needed!
For now I am happy with headless import, which remembers last settings, that was used in normal import dialog.