run a Fiji(imageJ) script from terminal on a macOS to process images.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Yao
Reply | Threaded
Open this post in threaded view
|

run a Fiji(imageJ) script from terminal on a macOS to process images.

Yao
I need to run a Fiji(imageJ) script from terminal on a macOS. Using the code
below.

/Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --headless -macro
~/desktop/testing.ijm.ijm
And the Fiji script I need to run is

dir = getDirectory("Where I need help");
run("Image Sequence...", "open=dir");
path=dir+"needsave.avi";
run("AVI... ", "compression=JPEG frame=5 save=&path");
close();
However I want the directory to be the current location in terminal. For
example:

MYs-MBP:~ csh;
[MYs-MBP:~] cd desktop/test/test2
[MYs-MBP:~/desktop/test/test2]
/Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --headless -macro
~/desktop/testing.ijm.ijm
and therefore I will process everything in test2 by using the Fiji script I
write.

I tried to use getDirectory("current"), but it kept saying no image, while
"desktop/test/test2" is the right place.



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: run a Fiji(imageJ) script from terminal on a macOS to process images.

Jerome Mutterer-3
Hi,

You could pass the desired directory to your macro as an argument:

/Users/jmutterer/Downloads/Fiji.app/Contents/MacOS/ImageJ-macosx --headless
-macro ~/Desktop/test.ijm /Users/jmutterer/Desktop/myDir/

will print: /Users/jmutterer/Desktop/myDir/

using this example macro:

// test.ijm
dir=getArgument();
print (dir);

The argument is a string, so you can't use tilde expansion, which is a
system feature, you'll have to use full path.
(unless you include something like dir = replace (dir, '~', exec ('echo
~')); )

Jerome

2018-05-22 1:18 GMT+02:00 Yao <[hidden email]>:

> I need to run a Fiji(imageJ) script from terminal on a macOS. Using the
> code
> below.
>
> /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --headless -macro
> ~/desktop/testing.ijm.ijm
> And the Fiji script I need to run is
>
> dir = getDirectory("Where I need help");
> run("Image Sequence...", "open=dir");
> path=dir+"needsave.avi";
> run("AVI... ", "compression=JPEG frame=5 save=&path");
> close();
> However I want the directory to be the current location in terminal. For
> example:
>
> MYs-MBP:~ csh;
> [MYs-MBP:~] cd desktop/test/test2
> [MYs-MBP:~/desktop/test/test2]
> /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --headless -macro
> ~/desktop/testing.ijm.ijm
> and therefore I will process everything in test2 by using the Fiji script I
> write.
>
> I tried to use getDirectory("current"), but it kept saying no image, while
> "desktop/test/test2" is the right place.
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>



--
Jerome Mutterer
CNRS - Institut de biologie moléculaire des plantes
12, rue du Général Zimmer
67084 Strasbourg Cedex
www.ibmp.cnrs.fr

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: run a Fiji(imageJ) script from terminal on a macOS to process images.

Curtis Rueden
In reply to this post by Yao
Note that this question was also posted on the ImageJ Forum here:

   http://forum.imagej.net/t/set-imagej-directory-from-terminal/11060

For the archives: you can get the current working directory from a macro as
follows:

   cwd = call("java.lang.System.getProperty", "user.dir");

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden
Did you know ImageJ has a forum? http://forum.imagej.net/


On Mon, May 21, 2018 at 6:18 PM, Yao <[hidden email]> wrote:

> I need to run a Fiji(imageJ) script from terminal on a macOS. Using the
> code
> below.
>
> /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --headless -macro
> ~/desktop/testing.ijm.ijm
> And the Fiji script I need to run is
>
> dir = getDirectory("Where I need help");
> run("Image Sequence...", "open=dir");
> path=dir+"needsave.avi";
> run("AVI... ", "compression=JPEG frame=5 save=&path");
> close();
> However I want the directory to be the current location in terminal. For
> example:
>
> MYs-MBP:~ csh;
> [MYs-MBP:~] cd desktop/test/test2
> [MYs-MBP:~/desktop/test/test2]
> /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --headless -macro
> ~/desktop/testing.ijm.ijm
> and therefore I will process everything in test2 by using the Fiji script I
> write.
>
> I tried to use getDirectory("current"), but it kept saying no image, while
> "desktop/test/test2" is the right place.
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html