Posted by
dscho on
Aug 17, 2009; 9:25am
URL: http://imagej.273.s1.nabble.com/String-Manipulation-in-Macros-tp3691475p3691478.html
Hi,
On Mon, 17 Aug 2009, Michael Schmid wrote:
> when a string argument contains spaces, don't forget to put square
> brackets around it:
>
> saveAs("Tiff", "["+path.substring(0,path.length()-4)+" - green.tif]");
This might be true for calls to run(<plugin>, <arguments>), but for
saveAs(<format>, <argument>)?
Let's see:
http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=ImageJA.git;a=blob;f=ij/macro/Functions.java;h=f7b4c55161330c39e0d5020e04677cb70b4f8002;hb=79c981f8f2c069644abcf8d1dca1a91863da85a1#l2357The definition of the saveAs() function in the macro interpreter does not
parse the argument string. How about IJ.saveAs()?
http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=ImageJA.git;a=blob;f=ij/IJ.java;h=81d903695d6df4f3e902acf3a962225fe0928312;hb=79c981f8f2c069644abcf8d1dca1a91863da85a1#l1342Note that the function with the ImagePlus parameter (which is called by
saveAs() without ImagePlus parameter) is defined a couple of lines below
the linked one.
The only thing that does with the path before handing off to a plugin
determined by the format is updateExtension() (defined below the 2nd
saveAs() function), which does not handle brackets at all.
But when handing off to a plugin, the brackets are added:
http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=ImageJA.git;a=blob;f=ij/IJ.java;h=81d903695d6df4f3e902acf3a962225fe0928312;hb=79c981f8f2c069644abcf8d1dca1a91863da85a1#l1406So it appears to me as if your suggestion would actually lead to file
names _including_ brackets.
Let's try:
run("Blobs (25K)");
saveAs("Jpeg", "[/tmp/bla with spaces.jpg]");
Uh oh.
java.lang.IllegalStateException: Output has not been set!
Removing the brackets makes the script work beautiully, spaces in the
filename and all.
Ciao,
Dscho