Skip to content, Skip to search

Changes

Scripting

2,782 bytes added, 12:56, 20 July 2018
Adding JAR-packaged scripts to the menu: Small fixes
{{ScriptingLearn|scripting}}ImageJ allows you to write scripts in several different languages.
= Getting started =
= Supported languages =
ImageJ's [[Script Editor]] supports many different languages. The following table summarizes the following languages:possibilities.
* {| class="wikitable"| colspan=2 style="background: #ddd; text-align: center; font-weight: bold" | Recommended options|-! [[Beanshell Groovy Scripting|BeanShellGroovy]]* | [[wikipedia:Groovy Scripting(programming language)|Groovy]]is a flexible and powerful scripting language, Java-like but less verbose and dynamically typed. Learn this, and using Java later (if needed) will become easier.* |-! [[Introduction into Macro Programming|ImageJ Macro]]* | style="white-space: normal !important" | The [[ImageJ 1.x]] macro language is less powerful than the other scripting languages, but is designed to be easy to learn and use.|-! style="white-space: nowrap" | [[Jython Scripting|Python (Jython)]]| [[Introduction into Developing Pluginswikipedia:Python (programming language)|JavaPython]]is a popular choice among scientists.* |-! [[Javascript Scripting|JavaScript]]* | [[wikipedia:JavaScript|JavaScript]] is a popular choice among web developers.|-! [[JRuby Scripting|Ruby (JRuby)]]| [[wikipedia:Ruby (programming language)|Ruby]] is another popular choice among web developers.|-! [[Clojure Scripting|Lisp (Clojure)]]* | [[Jython Scripting|Python wikipedia:Lisp (Jythonprogramming language)|Lisp]]is a popular choice among computer scientists.|-* ! [[Renjin Scripting|R (Renjin)]]* | [[JRuby Scripting|Ruby wikipedia:R (JRubyprogramming language)|R]]is a popular choice among scientists and statisticians.|-* | colspan=2 style="background: #ddd; text-align: center; font-weight: bold" | Other options|-! [[Scala Introduction into Developing Plugins|Java]]| You can code Java plugins in the Script Editor. This is the most difficult path, but also the most powerful.|-! [[MATLAB Scripting|ScalaMATLAB]]| ImageJ can interface bidirectionally with MATLAB. See the [[MATLAB Scripting]]page for details.|-! [[Beanshell Scripting|BeanShell]]Additionally, these languages can be installed via | [[httpwikipedia://fijiBeanShell|BeanShell]] is an old script language, maintained mostly for backwards compatibility.sc/Update_Sites update sitesIt is nearly 100% compatible with Java syntax, but so is [[Groovy]]:.|-* ! [[MATLAB Scala Scripting|MATLABScala]]| [[wikipedia:Scala (programming language)|Scala]]support is currently experimental, and has bugs.|}
= Script parameters =
== General key bindings ==
* {{Key|up arrow}}: bring the previously typed command.* {{Key|down arrow}}: bring the next typed command.* {{Key|enter }} or {{Key|return}}: execute the contents of the prompt.
== Multiline editing and keybindings==
= Adding scripts to the Plugins menu =
For the script to appear in the Plugin ImageJ menus, the following must apply: {{Box| text = ".txt" is not a supported script extension| width = 30%| float = right}}# The script file is saved in the <code>ImageJ.app/scripts</code> or the <code>ImageJ.app/plugins/Scripts</code> directory (or a subdirectory thereof).# The script name ends in a supported script extension. For example#* ".groovy" for groovy,#* ".js" for javascript,#* ".py" for jython,#* ".rb" for jruby,#* ".clj" for clojure,#* ".bsh" for beanshell, and#* ".ijm" for ImageJ 1.x macros.# The script name contains a '_' (underscore) character, e.g. "MyScript_.ijm".
# The script file is saved in the {{Fiji | Replace <code>ImageJ.app</pluginscode> with <code>Fiji.app</code> directory (or a subdirectory thereof).# 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.# 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 "<code>ImageJ.app/plugins" </code> 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 "<code>ImageJ.app/pluginsscripts/ScriptsFile</File" code> directory will add it to the ''File '' menu.
If you aren't able to find your script, you can always run the [[Using_the_Command_Launcher|Command Finder]] to verify its location (or absence).
 
Commands added to the menu in the described way can be called from other scripts. Use the [[macro recorder]] to get the required code for doing so.
 
== Adding JAR-packaged scripts to the menu ==
 
Scripts can be packaged in a JAR file for easier distribution to your colleagues and via [Update Sites]. For this purpose, [https://github.com/imagej/example-script-collection example-script-collection] can be used as the template Maven project.
 
Inside the example-script-collection jar, the scripts are in <code>./resources/scripts.</code> and therefore get added to the menu when the JAR is on the classpath (i.e. in <code>./plugins/</code> or <code>./jars/</code>).
 
ImageJ2 (and therefore Fiji) looks for scripts in subfolders of <code>./scripts/</code> as it is already described in the previous section, and for jars in <code>./jars/</code>. ImageJ1 recognizes plugins and scripts in <code>./plugins/</code>
= Running scripts in headless mode =
Emailconfirmed
25
edits