Login  Register

Re: run macro in command line

Posted by Wayne Rasband on Oct 02, 2009; 5:39pm
URL: http://imagej.273.s1.nabble.com/run-macro-in-command-line-tp3690941p3690942.html

 > I would like to know how to run imageJ with my images for
 > linking with an external homemade program.
 >
 > For example, I have an image in c:\program
 > files\imageJ\1.tif (image file) and 1smacro.txt (macro).
 > When I typed,  "java -cp ij.jar;.RunMacro 1smacro.txt" in
 > command line of c:\program files\imageJ, java could not
 > found "1smacro.txt". Would you give me an example for my
 > purpose? How can I let ImageJ know 1.tif as the input
 > parameter?

You can pass the image name or path to the macro as an argument using

    java -jar <path to ij.jar> -ijpath <path to ImageJ folder> -macro
1smacro 1.tif

The macro can retrieve the argument using the getArgument() function

   path = getArgument();
   if (path=="")
       exit("Argument is missing");
   open(path);

Here is a tested example that assumes the ImageJ folder is in
/Applications and that the "1smacro.txt" macro is in
/Applications/ImageJ/macros:

   java -jar /Applications/imagej/ij.jar -ijpath /Applications/ImageJ
-macro 1smacro abe.tif

ImageJ assumes the ".txt" extension if it is omitted. The ImageJ
command line options are described at the beginning of the source file
at

      http://rsb.info.nih.gov/ij/source/ij/ImageJ.java

-wayne