Login  Register

Re: run macro in command line

Posted by Jim Passmore on Oct 02, 2009; 5:05pm
URL: http://imagej.273.s1.nabble.com/run-macro-in-command-line-tp3690941p3690944.html

ImageJ Interest Group <[hidden email]> wrote on 10/02/2009 10:51:36
AM:
> Hi,
>
> On Fri, 2 Oct 2009, Lee S wrote:
>
> > 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).
>
>    java -cp ij.jar ij.ImageJ -macro 1smacro.txt
>
> > How can I let ImageJ know 1.tif as the input parameter?
>
> You have to specify it in the macro.  You can run
>
>    java -cp ij.jar ij.ImageJ 1.tif -macro 1smacro.txt
>
> too, but there is no guarantee that 1.tif has been fully loaded before
the
> macro is evaluated.
>
> Hth,
> Dscho

Coincidentally, I was mulling over this just this morning, and found the
following from Wayne (6/2/08):

> You can run a macro from the command line and pass a string argument
> using the -macro or -batch command line options. As an example, here is
> a macro that opens an image in the 'images' directory in the users home
> directory:
>
>    name = getArgument;
>    if (name=="") exit ("No argument!");
>    path = getDirectory("home")+"images"+File.separator+name;
>    setBatchMode(true);
>    open(path);
>    print(getTitle+": "+getWidth+"x"+getHeight);
>
> Assume it is named 'OpenImage.txt' and is located in the macros folder.
> Run the command
>
>      java -jar ij.jar -macro OpenImage blobs.tif
>
> and ImageJ will launch and "blobs.tif: 256x254" is displayed in the Log
> window. Note that ImageJ assumed the '.txt' extension and the
> Image/macros directory. Or run
>
>      java -jar ij.jar -batch OpenImage blobs.tif
>
> and the ImageJ window is not opened and the "blobs.tif: 256x254" output
> is displayed in the terminal window.
>
> -wayne


This approach allows you to specify the file on the command line, but use
the macro to open it, avoiding the timing problem.

Jim

----------------------------------------------
Jim Passmore
Research Associate
Sealed Air Corporation
----------------------------------------------