Is there a command line?

Is there an interactive command interpreter available for Fiji? I can type commands a macro and run them, but a real time option would be nice.

Hi @esiefker,

There is: Plugins > Scripting > Script Interpreter
and you can choose your preferred language .



The latest ImageJ daily build adds the Plugins>Macros>Interactive Interpreter command, which allows you to enter macro language and JavaScript commands and have them immediately interpreted. To upgrade, use the Help>Update ImageJ command and select “daily build” from the drop down menu.

Here is an example session:

[Macro interactive mode. Type "help" for info.]
  Type a function (e.g., "run('Invert')") to run it.
  Enter an expression (e.g., "x/2" or "log(2)") to evaluate it.
  Move cursor to end of line and press 'enter' to repeat.
  "quit" - exit interactive mode
  cmd+M - enter interactive mode
  cmd+shift+F - open Function Finder
  "js" - switch language to JavaScript
run("Blobs (25K)");
  Unrecognized command: "invert"
  There are no images open.

[JavaScript interactive mode. Type "help" for info.]
  ReferenceError: "sin" is not defined in nashorn:mozilla_compat.js 
img = IJ.openImage("");
  img["blobs.gif" (-8), 8-bit, 256x254x1x1x1]
ip = img.getProcessor()
  ip[width=256, height=254, bits=8, min=0.0, max=255.0]
  stats[count=65024, mean=103.26857775590551, min=8.0, max=248.0]
  TypeError: ip.GetStats is not a function in <eval>  
  stats[count=65024, mean=103.36157418799213, min=34.0, max=238.0]
ip.invert() // img.updateAndDraw() is automatic
[Exiting interactive mode.]

Hello Wayne -

Very cool!

This is not a feature request, but more a question to satisfy my
curiosity: Can something similar be done for jython (python),
itself an interpreted language? Would there be any impediment
to adding jython to the Interactive Interpreter (other than the
obvious issue of time and resources)?

Thank, mm

Also related:

1 Like

Support for Jython, and Groovy, BeanShell, Scala, etc., could be added but I prefer to keep the Interactive Interpreter simple and only support the macro language and JavaScript. I like JavaScript because it’s JIT-compiled and included with the Java runtime. JavaScript runs the Help>Examples>Language>Sphere program (size=4096) in 1/2 second, whereas Jython requires 12 seconds.

The script interpreter mentioned by @bogovicj above (Plugins > Scripting > Script Interpreter; included with Fiji) ships this functionality for several years now (for all supported script languages). I’d be interested if it matches your requirements, or if there’s anything missing to make it useful for you and others.

1 Like

Hi @mountain_man:

There has been a Jython Interpreter since Fiji was created, pretty much. Perhaps 10 years.

For unknown reasons, the Jython Interpreter and others were moved a few years ago to the fiji-legacy update site. Activate it to get them.

The new “Scripting Interpreter”, despite all many faults (, can run Jython code interactively.

The “Script Editor” now has a command prompt, AKA a script interpreter. So any language that is not compiled (like java) that runs in the Script Editor now has a script interpreter. The pull request is here and should be merged soon, bringing these new features of the Script Editor to a near-future fiji update.

1 Like

For the record: the reasons were explained here:

1 Like

Thanks for pointing to the original report on why the script interpreters were moved to the fiji-legacy update site. The report is unfortunate in that it announces the new Script Interpreter as replacing the old ones, when it didn’t: the new one has a number of severe issues, such as not being able to store the command history (a pretty basic feature), in addition to having undergone limited testing (resulting in e.g. using “:lang” commands to switch languages, when in e.g. clojure the ‘:’ is reserved for map keys), and a number of issues with the UI (lack of collapsible window displaying variables table, no info on what the variable table is for or why these variables are not available from the prompt).


Hello Albert (and John and Wayne et al.) -

Okay, it’s starting to look like an embarrassment of riches. Does this
look right?

  1. “Script Interpreter”
    Plugins > Scripting > Script Interpreter
    Been around for a while; I just didn’t know about it.

  2. “Interactive Interpreter”
    Plugins > Macros > Interactive Interpreter...
    New with Wayne’s recent Help > Update ImageJ...

  3. “Script Editor”
    New > Script...
    If I understand Albert correctly, the new “command prompt”
    feature will be coming soon, but is not yet part of stock Fiji.

  4. A “legacy” “Jython Interpreter and others,” not distributed
    with stock Fiji, but available from the fiji-legacy update site.

A couple of questions: Which to use for common tasks? Do some offer
features (other than the obvious issue of specific language support) that
would be of use in special cases?

If I install the “legacy” interpreter(s) where will they show up in the Fiji
menu system?

Thanks to all for letting me know that this functionality exists. It should
be a nice convenience when monkeying around.

Thanks, mm

Hi @mountain_man,

The “legacy” interpreters actually work, as opposed to the new “Script Interpreter” which has errors such as failing to save your entered command line history. These “legacy” interpreters will show up in the “Plugins - Scripting” menu.

For common tasks I use these “legacy” ones, been doing so for years.

Wayne’s new macro interpreter I haven’t tried. I prefer a full-fledged programming language like python and clojure over macros.

I feel obligated to push back on @albertcardona’s vehemence—I used the new Script Interpreter sometimes, and it works OK for me. It’s true that there are some bugs we need to fix, but implying it “doesn’t work” is highly unfair. It works for me and others. @mountain_man I suggest you simply try all available options for yourself and use the one(s) that work for your needs.

To complete your list above: there is yet another way to execute script one-liners, using the “hash bang” (#!) syntax in the search bar. It uses the same REPL instance as the Script Interpreter. Here is an example:

Okay, @ctrueden, now you’re just messing with my head.