home | lab | find me | science | publications | software | toolbox | site map

ImageJ Macro interpreter by example


Put the jar file into your plugins folder, and restart ImageJ.

Opening images

Image paths examples for Windows:

Linux and Unix users should know already how their file paths looks like.

Running ImageJ commands

Doing commands with magic on (just type in: magic )

Extended example:

User types:Screen prints:
magic--> magic is ON
open baboon.jpg \> open("/Applications/ImageJ/baboon.jpg");\
makeRectangle 10,10,50,100 \> makeRectangle(10,10,50,100);\
setColor 0,0,255 \> setColor(0,0,255);\
fill()> fill()

Just like in a proper shell, if the ending backslashes are removed, the code is executed step by step as it is typed in.

Recording, editing, copying and running macros

If before starting to type the macro the user typed 'record mymacro', all the typed lines are saved into macro mymacro. At any point 'exec mymacro' can be called, even before typing 'stop' to end the recording. Typing 'view mymacro' prints the macro without executing it, and 'list' shows the names of all recorded macros. Type 'save mymacro' to open a file dialog and save it into a file.

Alternatively, select the macro text from the screen and choose the 'Execute Selection' or 'Save Selection' or 'Copy' options from the popup menu.

Recorded macros can be edited. Type 'front' to view which macro is the active one, or 'front mymacro' to start editing (recording into) 'mymacro'. The 'erase -l 10' erases line 10 from the front macro, and 'erase 4' erases the last 4 lines of the front macro.

The 'exec' function will try to execute macros from the recorded list, the current directory and the ImageJ macro directory. Thus typing 'exec Sine' will execute the SineCosineTable.txt macro, unless there is a macro whose name starts with 'Sine' in the recorded list or a text file in the current directory with such a name starting. Macros from text files executed this way will be cached into the recorded list.

If a macro .txt file contains more than one macro defined, the macro interpreter won't execute any of them. Just select the text from the screen and choose 'Execute Selection' from the popup.

Last updated: 2012-05-08 11:10 Zurich time. Copyright Albert Cardona.