Scripting

Scripting
Topics
Overview
Parameters
Batch processing
Script Editor
Auto Imports
Templates
Running headlessly
Comparisons
Toolbox
Languages
BeanShell
Groovy
ImageJ Macro
JavaScript
Lisp (Clojure)
MATLAB
Python (Jython)
R (Renjin)
Ruby (JRuby)
Scala
Multithreading
in Clojure
in JavaScript
Examples
Chess in Jython

ImageJ allows you to write scripts in several different languages.

Getting started

  • Press the [ key to open the Script Editor (or Shift-[ to open the Script Interpreter).
  • Optionally, choose a template from the Templates menu to get you started.
  • Otherwise, choose your language from the Language menu.
  • Grab code snippets for common tasks from the Scripting toolbox.
  • See Scripting comparisons for a side-by-side comparison of scripting languages.
  • See Category:Scripting for a list of all scripting-related pages on this wiki.

Supported languages

ImageJ's Script Editor supports the following languages:

Additionally, these languages can be installed via update sites:

Script parameters

There is a universal @parameter notation available across all scripts for declaring inputs and outputs. This approach is preferred to using ImageJ 1.x GenericDialog because it is totally agnostic to the user interface, allowing such scripts to run in a variety of contexts.

See the script parameters page for details.

Using an interpreter

All scripting languages use the same basic interpreter, with the following common features.

General key bindings

  • up arrow: bring the previously typed command.
  • down arrow: bring the next typed command.
  • enter or return: execute the contents of the prompt.

Multiline editing and keybindings

You can enlarge the prompt by dragging the middle bar.

  • Shift+ Enter: create a new line within the prompt.
  • Shift+: move to the line above within the prompt.
  • Shift+: move to the line below within the prompt.

Selecting and executing text from the screen

On selecting text, a popup offers to:

  • copy
  • execute
  • save to a new file

Using the script editor

You can create, edit and run scripts using the built-in Script Editor. For details, please see the Script Editor documentation.

Adding scripts to the Plugins menu

For the script to appear in the Plugin menus, the following must apply:

  1. The script file is saved in the ImageJ.app/plugins directory (or a subdirectory thereof).
  2. The script name ends in a supported script extension. For example, ".js" for javascript, ".py" for jython, ".rb" for jruby, ".clj" for clojure, and ".bs" for beanshell script. 'NOTE:' ".txt" is not a supported script language.
  3. The script name contains a '_' (underscore) character, e.g. "MyScript_.ijm"

The extension will be stripped and any underscores will be turned into spaces before the script is added to the menus.

Scripts in the top-level "plugins" directory will appear at the bottom of the Plugins menu. Scripts can be placed in other menus by by nesting subdirectories, for example placing a script in the "/plugins/Scripts/File" directory will add it to the File menu.

If you aren't able to find your script, you can always run the Command Finder to verify its location (or absence).

Running scripts in headless mode

See the Scripting Headless page for instructions on executing scripts headlessly.