Skip to content, Skip to search



1,185 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 =
= 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></code> or the <code></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, and #* ".bsbsh" for beanshell script, and#* ". 'NOTE:' ijm"for ImageJ 1.txt" is not a supported script languagex macros.# The script name contains a '_' (underscore) character, e.g. "MyScript_.ijm". {{Fiji | Replace <code></code> with <code></code>}}
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>" </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></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, [ 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 =