Difference between revisions of "Scripting"

(Add a link to the script editor)
(Running Scripts in Headless Mode: May '09 is no longer "quite recently"...)
Line 46: Line 46:
   fiji --headless -eval 'run("Refresh JRuby Scripts",""); run("test ruby","");' -batch
   fiji --headless -eval 'run("Refresh JRuby Scripts",""); run("test ruby","");' -batch
(If this gives you a NullPointerException in RefreshScripts, then you need a newer version of Fiji - a bug with this was fixed [http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=fiji.git;a=commit;h=590059c5f8c74e47d4f648c5055fc72fa2074707 quite recently].)

Revision as of 09:28, 28 October 2010

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 keybidings

You can enlarge the prompt by dragging the middle bar.

  • shift + enter: create a new line within the prompt.
  • shift + up arrow: move to the line above within the prompt.
  • shift + down arrow: id, down.

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 Fiji's script editor. For details, please see the Script Editor documentation.

Creating scripts and using "refresh scripts"

On startup, ImageJ will run all "refresh scripts" plugins, one for each supported language. This will result in all scripts present within the plugins folders to be added to the menus.

To run a script, just select it from the plugins menus.

If you edit a script that is already placed in the menus, you don't need to do anything else: just save the text file and run it again by selecting it from the menus.

If you add a new script and ImageJ is running, just go to Plugins - Scripting and run the appropriate Refresh * Scripts for the language.

For the script to appear in the Plugin menus, it needs to terminate in the appropriate file extension. For example, ".js" for javascript, ".py" for jython, ".rb" for jruby, ".clj" for clojure, and ".bs" for beanshell script. The script must also contain a '_' (underscore) in the name. The extension will be stripped and any underscores will be turned into spaces before the script is added to the menus.

Running Scripts in Headless Mode

If you want to run scripts in headless mode (i.e. without the GUI, by invoking fiji with the --headless option) then you have to make sure you run the appropriate "Refresh ... Scripts" plugin first. Also, you need to append -batch to the command. For example, if you have a script called test_ruby.rb, which appears in the Plugins menu somewhere as "test ruby", then you can run that with:

 fiji --headless -eval 'run("Refresh JRuby Scripts",""); run("test ruby","");' -batch