Login  Register

Re: macro parameter from command line

Posted by Michael Schmid on Jun 02, 2008; 2:09pm
URL: http://imagej.273.s1.nabble.com/macro-parameter-from-command-line-tp3696096p3696098.html

Hi Federica,

I see two ways: write all of macro from the batch file, e.g.
under windows
   echo run("Open...", "open=%myFile%"); >myMacro.txt
   echo run("Smooth"); >>myMacro.txt
   echo ... >>myMacro.txt
or under Linux
   echo run("Open...", "open=$myFile"); >myMacro.txt
   echo run("Smooth"); >>myMacro.txt
   echo ... >>myMacro.txt
(note that variable substitution such as $myFile takes
place in spite of the double quotes. Single quotes would
prevent it).

And then start ImageJ with that macro "myMacro.txt".
This will be fine for short macros.


The other way is writing the arguments into a file with fixed
name that your macro reads with
   string = File.openAsString(path);
If the file contains arguments delimited by some character,
e.g. tab "\t", newline "\n", etc, you can use
   args = split(string, delimiters)
to get the arguments as args[0], args[1], etc.

The second option is probably the better one for long macros.


By the way, in a macro
   run("Open...", "open=/tmp/anyimage.tif");
could be replaced by the more simple command
   open("/tmp/anyimage.tif");

Hope this helps,

Michael
________________________________________________________________


On 2 Jun 2008, at 15:15, 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