How can I save the log window in Javascript?

I’m using Fiji and Javascript - I would like to save the log window into a file. I haven’t found a command that does that in Javascript - I looked at the Java API, but I haven’t found the answer. (I know how to do it in the macro language) Does anyone know how to do it?


Hello Avital, here is a simple example which works for me:

IJ.saveAs("Text", "C:\\Users\\Avital\\Desktop\\Log.txt");

Executed in the simple editor: New->JavaScript

Thanks, but it doesn’t work for me. It says: “No log window found.”

It works for me on Windows. Do you execute the whole example or doesn’t it work with your custom JavaScript code?

What is the name of your log window you want to save?

You can record the JavaScript steps with the macro recorder (select JavaScript in the recorder and then save your log window to record the action - eventually you see a difference?).

Thanks - I executed your code as is and still got the error message. Except for importing IJ and changing the path to a Linux path, I didn’t change anything. I’m using a mac. In Fiji’s Javascript, the screen is divided - the top part displays my code and the bottom part prints out the output. It’s like a console window - I don’t see a name for this window. I couldn’t find a way to save it in the graphical user interface either.

Dear Avital,

that’s why I noted to use the classical ImageJ JavaScript editor in FIJI. (Plugins->New->JavaScript).
Indeed in the default FIJI script editor which you use it doesn’t work (script editor selected to execute JavaScript).

1 Like

Great! Thanks - I was unaware of this option. It’s very useful!

Sounds like a bug. Would you mind filing an issue for it?

Possible bug reported here:

Thank you!

It looks like the issue is just a missing import statement. ImageJ2 does not provide any auto-imports. So this is working as intended.


That sounds like a different problem. Maybe also a bug in ImageJ2’s Script Editor?

On OS X 10.11, the IJ.selectWindow("Log"); command works for me as long as the Log window is actually on screen. (E.g.: if you write IJ.log("Hello"); earlier in the script.) If there is no Log window, then of course it complains that no log window can be found as expected.

Thanks Curtis. I should have read the right JavaScript documentation:

whereas I read:

which does not suggest to use the “packages” prefix in the imports (which was my first suspicion that some imports where missing).

Here now the complete script which works for me:

IJ.saveAs("Text", "C:\\Users\\Avital\\Desktop\\Log.txt");

Note that and are (AFAIK) maintained solely for backwards compatibility. Wayne uses, rather than the old or rsbweb subdomains. (Ideally they would simply issue 301 redirects, but the NIH server admins don’t seem to care too much about those sorts of details.)

Also, the portal provides a full mirror of all ImageJ 1.x content. So you can always write e.g. rather than the version. This might actually be more future-proof, since there are impending issues with and HTTPS. In general, we have no control over server configuration, but full control over, so I can make sure those URLs keep working for the foreseeable future.