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 |
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 |
In reply to this post by federica viti
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 > |
Free forum by Nabble | Edit this page |