Macro to save image

I have a macro in which I renamed an image and then I want to save it as .tiff

The only option I found is SaveAs in which I have to write the whole path directory plus the name of the file.

Is there not an easy way just to save the image directly into a folder without the need to type again the name of the image?

Hi
@mvizoso
I always use the:
plugin -> macro -> record
then File -> SaveAs -> (choose the folder).
It’s very fast.
Greetings

I use this Once at the beginnig of code:
dir2 = getDirectory("Choose Output Image Directory ")

Then when I want to save
saveAs(“Tiff”,dir2+“Whatever you want”);
I usually use
saveAs(“Tiff”,dir2+t+“newlabel”);
where t is the title of the image and newlabel is a tag about the process I’ve just used

Hi, it does not work for me. When I type getDirectory a Windows10 opens to select the directory I want. Even if I select one when I try to save it in dir2, ImageJ complains saying that it does not recognize dir2 variable.

Hum… I use that command in the Graphical user interface often, but I am on a mac. do you have the dir2=getDirectory(): part of the line not just get Directory? Just checking.

Hi @mvizoso,

You can print("dir2 is "+dir2); immediately after the getDirectory() call @susan-sheehan suggests. It should contain the path and that should be shown in your log window.

I notice that you ask quite a few questions on macro programming (syntax). If you are learning to program macros, you may consider using ImageJ1 for a while, as it has a Debug facility that ImageJ2 (FIJI) is missing (effectively).

In ImageJ1 you can inspect your variables at every step your code makes,you can hop skip and jump over lengths of codes by clever use of the if() then debug() construction and do many more handy things to see what is going on (inspecting array contents comes to mind). Once a macro is operational, you can move to FIJI if that is necessary for some extended feature FIJI has, and ImageJ1 hasn’t.

Many thanks for all your help and suggestions. I was indeed looking for a debug facility that check for errors, what a surprise that ImageJ has the corrector and imageJ not.

I will try to add this to my macro, because now I am writing the same whole path over and over again.