User interaction#
A macro is nice, but many errors come from hard-coding values or paths in the script. You forgot to change one parameter? Well, everything crashed and you are looking at 1h of debugging.
To make macros and scripts friendlier, the ImageJ2 team came up with script parameters
. These automatically generate a graphical user interface (GUI)!
Simple script parameter#
Here is a simple example to place at the start of a script:
#@ String (label="Please enter your name", description="Name") name // (1)!
#@output String greeting // (2)!
greeting = "Hello, " + name + "!" // (3)!
- This is the parameter declaration, it has a type (
String
) and a name. - Output declaration, necessary if you want to print something to the user or show an image.
- The script itself. The
name
variable is automatically filled by the GUI.
Try it!
The first thing to notice is that the name is never hard-coded in the script!
Note
There are many types of parameters. For more info, check out the parameters documentation.
Note
Have you noticed that the greeting
was prompted to a different window than usually?
This is because the parameters
are a feature of scripts
in ImageJ2. The print
function of the macros is an old feature belonging to ImageJ1.