Posted by
Wayne Rasband on
Jun 02, 2008; 3:30pm
URL: http://imagej.273.s1.nabble.com/macro-parameter-from-command-line-tp3696096p3696097.html
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
On Jun 2, 2008, at 9:15 AM, federica viti wrote:
> Hi everyone,
> I'm working on ImageJ 1.40 in batch mode. I cannot find anywhere if
> it's
> possible passing parameters to a macros directly by command line. I
> mean
> something like this:
> ./jre/bin/java -jar ij.jar -batch macros/Try.txt < inputTry
>
> I cannot use dialog box because I'm working without GUI and not
> interactively.
> Particularly I need to pass the macro the name of a file. I thought to
> write
> the name in a file and use the option of the open function to read it
> and
> open the file .. something like the example I found on line:
>
> run("Open...", "open="+getDirectory("plugins")+"README.txt");
>
> but the name of my file is composed by variables, so I have to include
> everything in a script to decode the name and it cannot read as a txt
> file.
>
> Do you know some way to help me?
> thank you very much
> Federica
>