Opening image file with open() and auto-clicking on OK

Tags: #<Tag:0x00007fd560e7c9e8> #<Tag:0x00007fd560e78730> #<Tag:0x00007fd560e73de8>


I’m new to the ImageJ language. I want to create a macro in ImageJ to extract the images from multiple hyperstack files. I mananged to get a list of hyperstack files (*.cxd) with the getFileList(), but when I run open() on each of them:

list = getFileList(dir)
for (i=0; i<list.length; i++)

I am prompted with a ‘Bio-Formats Import Options’ dialog box, where I only need to click OK. This is expected, but I was wondering if it is possible to ‘auto-click’ the OK button such that the macro does not require user interaction.

Thank you


Hi @tomas !

Welcome to ImageJ and the Forum!

So… Here are some super helpful links to get you started with Scripting in ImageJ:

There is a great script example:

 * Macro template to process multiple images in a folder

#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix

// See also for a version of this code
// in the Python scripting language.


// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
	list = getFileList(input);
	list = Array.sort(list);
	for (i = 0; i < list.length; i++) {
		if(File.isDirectory(input + File.separator + list[i]))
			processFolder(input + File.separator + list[i]);
		if(endsWith(list[i], suffix))
			processFile(input, output, list[i]);

function processFile(input, output, file) {
	// Do the processing here by adding your own code.
	// Leave the print statements until things work, then remove them.
	print("Processing: " + input + File.separator + file);
	print("Saving to: " + output);

This script utilizes Script Parameters for dealing with folders/files… they are so helpful to use!

There is also a great working example using that same code (opening files via Bio-Formats automatically) in the Scripting Workshop - on this slide.

Hope this helps!

eta :slight_smile:


Hello eta,
thank you very much for the examples and the links, they are very helpful and are exactly what I needed.

Best regards!


Great @tomas - I’m glad that helped! And if you have more questions after all of this… post again. We are here to help!