Trouble Scripting in FIJI



Hi all,

I’m very new to FIJI, coding, and scripting, and need some help troubleshooting a laughably simple macro that stopped working after the most recent FIJI update. Before the update, all I had to do was run the macro and choose an input .lif file, and FIJI would open every series in the file (every series was a z stack view of a different macaque brain region), separate them into separate .tif files, then I would select the output folder I wanted to save them to. Some of my .lif files can still be processed just fine; when the series of views were collected by simply selecting regions of brain using the confocal microscope, each image was labeled as “Series 1 through n” by the microscope, followed by the naming convention chosen for that experiment (Note that the naming convention doesn’t get added until I’ve chosen an output folder. I’ve included a screenshot of what it looks like when I open a .lif file that works directly in FIJI).

For the .lif files that crash the macro, the fields of view were collected first by the grad student selecting a random spot to orient himself, then using the “Mark and Find” function of the microscope to pre-select the spots he wanted to image, then allowing the microscope to collect each image. FIJI will open the first series in the file, save it to my selected output folder, and then I get the error shown below when I try to save the second series in the file to any selected folder.
When I open the problematic .lif files in FIJI directly and it asks which of the series I’d like to open, they’re labelled differently; all of the fields of view are still preceded by “Series 1 through n,” but the first randomly-selected field of view is labeled “Series001”, and the following fields of view are labeled “Mark and Find/Position001 through n” or “Mark and Find001/Position1 through n” depending on the microscope used (I’ve included an example of each below).
I’m guessing the problematic thing here is the “Mark and Find” addition to the name, which my macro doesn’t know how to account for. Either the addition of that label is the problem, or the mismatch between the Series number (n) and the Mark and Find position number (n-1). Unfortunately I don’t know how to selectively remove the first series from the .lif file, so the series number and Mark and Find position number match up, so I haven’t been able to test that. I’ve included a screenshot of my macro below; I think the problem is at line 10. The Series number is defined, and the macro is told to begin at Series 1 and continue running until Series n is opened, but maybe since the position isn’t defined, it gets stuck. Any help is very much appreciated!


Hello Matthew -

I will probably not be able to help you with your problem, but let
me ask for some additional detail that may help others help you.

Could you post both your script and error message as text, rather
than as images?

You show the error message in a pop-up window. Is there any
way you can capture more detail for the error. Since it says
IOException, perhaps you can get a full java stack trace (as
text). You might find that in Fiji’s Console / Log window. Or
perhaps you could start Fiji from the command line, and maybe
a stack trace will be written to your command-prompt window.

Thanks, mm


Hi Matthew @JungleJim4322 ,

I think the problem you are facing comes from the fact that the image title of the “mark_and_find” series contains a slash (that then translates as a backslash when rendered as a full path in Windows).

So, when creating the output path in line 12, you end up having a non-existing path, e.g.:

E:\Confocal Images\OutputTest\25X Microglia.lif - Mark_and_Find\

In this case my guess is that your original destination folder was:

E:\Confocal Images\OutputTest\

but the image name of the 2nd series resulted as:

25X Microglia.lif - Mark_and_Find/Position001

so the concatenation in line 12 created a mess.

To make a quick fix for this, I would swap line 12 for these two:

filename = replace(getTitle(), "/", "-"); //get rid of problematic slashes in title
out_path = getDirectory("Choose a Directory") + filename+ ".tif";

I hope this helps.



That helps a ton! I went over the problem with the grad student I’m working with yesterday and we noticed the slash/backslash conversion (it only took me 3 days to notice haha). I’m going to try what you suggested, but hopefully this will all turn out to be a nonissue, since the problematic images came from an unnamed practice run with the confocal microscopes.


Update: That worked perfectly! You’re a lifesaver, thank you so much!


Glad to know! :grin:


If you don’t mind me asking, was there a resource you used to learn the IJ1 Macro language? It seems like it’d be a very useful skill for me to get more familiar with it.


Not at all!
You can gather most of the basics by following the online documentation:
There are many specific tricks in the example macros that are linked in those two pages, and a lot of other examples here:

There’s also a really nice introduction here: , with links to lots of resources

I personally learnt quite a bit from reading examples from around the web. You can also get a lot of insight by looking at the code and conversations posted in this forum. I’ve found some really elegant solutions to specific problems that appeared here.

Happy learning!


Thank you again, I’ll start reading up!