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 .

John

4 Likes

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.]
help
  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
x=2
  2.0
x/3
  0.6666666666666666
sin(PI/3)
  0.8660254037844386
run("Blobs (25K)");
run("invert")
  Unrecognized command: "invert"
run("Invert")
close("*")
run("Invert")
  There are no images open.
js

[JavaScript interactive mode. Type "help" for info.]
n=3
  3
n/4
  0.75
sin(PI/n)
  ReferenceError: "sin" is not defined in nashorn:mozilla_compat.js 
Math.sin(Math.PI/n)
  0.8660254037844386
img = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
  img["blobs.gif" (-8), 8-bit, 256x254x1x1x1]
ip = img.getProcessor()
  ip[width=256, height=254, bits=8, min=0.0, max=255.0]
ip.getStats()
  stats[count=65024, mean=103.26857775590551, min=8.0, max=248.0]
ip.blurGaussian(5);
ip.GetStats();
  TypeError: ip.GetStats is not a function in <eval>  
ip.getStats();
  stats[count=65024, mean=103.36157418799213, min=34.0, max=238.0]
img.show()
ip.invert() // img.updateAndDraw() is automatic
quit
[Exiting interactive mode.]
5 Likes

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 (https://github.com/scijava/scijava-common/issues/308), 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 https://github.com/scijava/script-editor/pull/28 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).

See: https://github.com/scijava/scijava-common/issues/308

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.

3 Likes