Pb with macro with parameter name having ] character


I have some files with name ending with a square bracket ] , so when I record my plugin it will do something like this : run (... "image=[myfile[01]]")
but when I check the name of the file in the plugin the ] has disappeared and the name of my file is simply myfile[01 without the ending ], that is a bit annoying :wink: .

Thanks for any help


1 Like

Can you please give a complete macro command that does not work for you? Because on my machine


with a text file containing “print(“hello World”);” placed in the macros folder just writes Hello World to the Log window. Notice my file has no (hidden) extension.

Hi @eljonco,

Thansk for your reply, if you want to try to reproduce the error run the following code :
1/ compile and run the code
2/ with macro record, record a macro that will run the plugin, should berun("TEST ", "name=[my image[01]]");
3/ check the log

import ij.IJ;
import ij.ImagePlus;
import ij.gui.GenericDialog;
import ij.plugin.PlugIn;

public class TEST_ implements PlugIn {
	 String name;
public void run(String arg) {
	IJ.log("name "+name);
	private void showDialog() {
		GenericDialog gd = new GenericDialog("TEST");
		gd.addStringField("name", "my image[01]");
		name = gd.getNextString();

// the macro using recording macro 
// run("TEST ", "name=[my image[01]]"); 



Hi @Wayne and devs,

I think I found the problem, it is in Macro.java, the function getValue :
} else if (options.charAt(0)==’[’) {
index = options.indexOf("]",1);

I think it should be lastIndexOf, in case parameter name has a ] inside the value.



PS : sorry for double posting

This bug is fixed in the latest ImageJ daily build (1.52e11). Code changes can be viewed at

I don’t get this: the bracket syntax is particularly useful for file names with spaces; now how about a file name like this one:

image channel[01] position[02].tif

When I put it into an option string, it would look like this:

run("my command", "param1=[image channel[01] position[02].tif]");

and would not be parsed correctly, IMHO.
The same goes for the suggestion by @ThomasBoudier, as lastIndexOf wouldn’t help in this case.

Am I missing something?

The latest daily build (1.52e12) can handle file names like this one but it can’t handle names with mismatched brackets. Source code changes are at

1 Like