Error creating text window

Tags: #<Tag:0x00007fd546dd4eb0> #<Tag:0x00007fd546dd4ca8>


I’m new here, but been using macro programming for a while. I got an unexpected error while programatically creating a new text window [using run(“Text Window…”,"name=…] using .txt as name suffix. It looks like it creates an additional macro with .ijm suffix instead.

This issue relates to version 1.51n of ImageJ provided by Fiji. I’ve got no such issue using version 1.49v from NIH.

I’ve got a workaround by removing the .txt suffix from the window name which it is oddly renamed with the .txt suffix automatically appended as soon as you get it saved by using the [saveAs(“Text”,…] command within the macro. That was expected as it comes to the saved file name but NOT to the window name.

It looks like a less than desired behaviour to me. Wondering if someone else got the same kind of trouble and a more interesting workaround. Thanks for all.


Good day Flavio Betti,

not sure whether
run("Text Window","name=MyText.txt");
is allowed.

The macro recorder records
run("Text Window");
without any naming option.

I think saving is the way to go.




This appears to be a Fiji bug.

run(“Text Window…”, “name=MyText.txt”);

works as expected using ImageJ 1.51q.


Good day Wayne,

I didn’t realize the difference between “Text Window” and “Text Window…”, but

run("Text Window…", "name=MyText.txt");

leads to the error message:

Unrecognized command: “Text Window…”

when run from a Macro.txt window.

ImageJ 1.51q; Java 1.6.0_65 (64-bit); macOS 10.11.6



It works if the ellipse consists of three points “…” and not "…"
Sorry for the confusion that is due to the text editor (copy/paste).


Dear Herbie, thanks for your returns. I just followed your suggestions, and got interesting results.

By suppressing the remainder statements of the run command (name and so on), I surprisingly (in a negative sense) got the same issue under 1.51n, the only difference being I got a guide named “Untitled.ijm.ijm” instead - bad…

With 1.49v, I got a real text window named “Untitled.txt” under 1.49v (good anyway). Note that in this case, I did not save anything, only ran the run(“Text Window…”) command and still got the .txt suffix anyway which is not bad at all.

I also tried run(“Text Window”) instead of run(“Text Window…”) with the latter opening a dialog box asking me for the name, window size and a checkbox for menu (the former doesn’t ask for anything - just goes for it).

Right now, I can’t help but think ImageJ 1.49v is a charm, and 1.51n sucks - at least regarding this issue. Thanks again!



It’s best to use the recorder to generate macro code. This is what I get when I record the Plugins>New>Text Window command:

run("Text Window...", "name=MyText.txt width=80 height=24 menu");

This can be simplified to

run("Text Window...", "name=MyText.txt");


Wow! So it’s got to be a bug! I’ll strive to find 1.51q right now. Thanks for the clue, Wayne! I’ll check back to confirm the fix. Thanks again,



This is really interesting because there seem to be two ways of getting a text window:

Plugins >> New >> Text Window...


File >> New >> Text Window

Obviously I’ve recorded and used the latter…

Thanks anyway



Things went out straight, now that I have managed to upgrade to version 1.51q - thanks!

Indeed, it also worked out fine with my previous 1.49v. Only the Fiji distribution of 1.51n had the bug. Great clue - thanks again!



I think this might be “intended behavior”, as in Fiji, the legacy text editor (that doesn’t support syntax highlighting and only supports a limited subset of the available scripting languages) is supposed to be replaced by the more feature-rich script editor.
So it might rather be considered a bug that the “old” text window still opens when no extension is provided, because it leads to this unfortunate confusion you experienced.

Is there a reason why you still need the simple text window? I.e., is there anything you can’t do with the script editor that forces you to require the legacy text window? In this case, it would be good to know your use case, as the behavior of the script editor could be improved accordingly. (The development of open source software depends on community feedback, so thanks for bringing this up.)


Dear Jan, thank you for your questions.

I see your point about “intended behaviour”. I got stuck with the error message from my previously written macros, making them not compatible with Fiji.

It’s puzzling for me that they give rise to a double suffixed “Untitled.ijm.ijm” guide on the script editor instead of a fresh “Untitled.txt” window.

A script editor is a good thing. On a daily basis, I use Notepad++ instead of a legacy text window. Setting language as “JavaScript” gives reasonable syntax highlighting. Just be careful not to save your macros as “Macro.jsm”!

Back to the problem, I am most probably missing a proper way of putting text out using Fiji. My needs are rather simple: exporting measurements results to a spreadsheet. Not the regular results from the ROI manager; just strings and numbers (converted to string using “d2s”) generated within the macro.

After creating a fresh text window, I use several “print” commands to fill it with the desired output to be imported by the spreadsheet. It just didn’t work out with version 1.51n. Happily, it did OK with the non-Fiji version 1.51q (thanks, Wayne!)

Provided I discover a better way of overcoming this, I may give Fiji a second try. Thank you for the support!



Sorry to hear about your frustration. Rest assured that the ImageJ and Fiji developers try to be fully backwards-compatible, but it can still happen that some things break as they cannot be aware of all possible use cases.
Fiji (and with it, ImageJ2) has a lot of advantages over ImageJ 1.x, the updater and full scripting support being only two of them.

Yes, the double .ijm suffix can be a little annoying, it’s a separate issue that has been around for while, and none of the ImageJ developers has taken time to fix it, probably because of more important priorities. If you agree it should be fixed, and don’t want this issue to be forgotten by the developers, you can help by creating a new issue in the script-editor repository.

Yes, I also think that Notepad++ is an essential tool. Nevertheless, inside ImageJ I do prefer the script editor, as you can run your ImageJ scripts right from within the editor (without the need to save them as files first) while also having proper syntax highlighting for all the supported languages (IJ1 Macro and others).

But now back to your original problem:

I think taking the detour via a new text window is overly complicated: the print() macro function supports printing the output to a file directly (see also the SaveTextFileDemo.txt example macro).

From your description, I suppose you have a macro similar to this one:

resultArray = newArray("result1", 3.0, "result2", 5.2, "result3", 10);

run("Text Window...", "name=Results");

for (i=0; i<resultArray.length; i+=2) {
	print("[Results]", resultArray[i] + "\t");
	print("[Results]", resultArray[i+1] + "\n");

run("Text...", "save=C:\\temp\\Results.txt");

Now, using the print function to directly write to a file, you can do:

resultArray = newArray("result1", 3.0, "result2", 5.2, "result3", 10);

f ="C:\\temp\\ResultsDirect.txt");
for (i=0; i<resultArray.length; i+=2) {
	print(f, resultArray[i] + "\t" + resultArray[i+1]);

With one of the more powerful scripting languages, e.g. Groovy, you can do the same even more efficiently (you’ll see the advantages when you perform more complicated tasks):

results = [ result1: 3.0, result2: 5.2, result3: 10 ]

file = new File("C:\\temp\\ResultsGroovy.txt")
file.withWriter { out ->
	results.each { key, value ->

I hope I could transmit some of the reasons why I definitely recommend to try Fiji :slight_smile:

If you need help adjusting your macros (or even transforming them into a less limited script language), don’t hesitate to ask here on the forum by opening a new topic.


I have no reason to doubt it - only resentful of my own lack of skills!..

I think it can be worthwhile!

I’ll definitely try it!

At this point of my work, ImageJ 1 macros have already proved to be useful enough to make me feel greatly indebted to them, thanks to the rich built-in functions library. Of course, it would be even greater if it could handle arrays with dimension greater than 1. Should ImageJ 2 be able of doing it?

I can’t be thankful enough for all your invaluable help. Regards,



I definitely got where I wanted by using your most valuable second advice (“using the print function to directly write to a file”). Better yet, I was able to merge results from multiple analysis (multiple executions) by using the command File.append instead of (it works with a preexisting file that can even be an empty file previously created by Notepad, for instance). I am absolutely thankful.



the same here, thank you a lot, i’ve also benefitted a lot from that function!