How to make a macro ask for a file name before saving a generic Results.xls file?

While processing images with the Ridge Detection plugin, I save the results in the default XLS format, but the old filename ‘Results.xls’ is always overwritten without asking for my input.

How to modify the macro to stop before executing the SaveAs… step and ask for the preferred folder and filename?

Good day,

this works for me:

nme=split(getTitle(), ".");
nme=nme[0]+".xls";
//
run("Ridge Detection", ... );
//
Table.rename("Results", nme);
path=getDirectory("Where to save the results?");
saveAs("Results", path+nme);

Maybe you read-up here:
https://imagej.nih.gov/ij/developer/macro/functions.html

HTH

Herbie

PS:
If you prefer to not automatically set the file name you can use:

//
run("Ridge Detection", ... );
//
saveAs("Results");

Then you must not only set the file name but always change the suffix from “txt” to “xls”.

@anon96376101, thanks for your quick reply. I’d like to modify the script slightly differently: the ‘Summary’ table must be renamed to ‘Results’, but the SaveAs XLS file should take the name of the image file with an added _Results.xls suffix (instead of the usual .jpg (I don’t use the tiff format, since I don’t see any effect on the results, and the image files are much larger) and be saved in the same folder where the image file exists.

I found a related post: Macro: How can I create an output files with a name related to the input file?, but my amateurish fiddling with the code did not work out as expected… :wink:

Sorry but what you write now is quite different from your original post.

Did you try my short macro. It names the Results window after the image file, so it is easy for you to append “_Results.xls” instead of “.xls”.

Why is it that

the ‘ Summary ’ table must be renamed to ‘ Results

??

and what do you finally like to save?

BTW, a Results table is never saved with suffix “.jpg”
This appears quite confusing to me.

In any case never ever save images in JPG-format if you do any analyses on them. JPG-compression is lossy and introduces artifacts that cannot be removed.

Did you try to code macros yourself yet?
Please consult the link given before.

Regards

Herbie

Yes, my post may have been a bit unclear due to that egg nogg+bourbon concoction yesterday evening… :wink: Here is what I really want to do in the final part of the macro (the early part works well):

  1. Go to the Summary window and rename it to Results
  2. Go to the new Results window, the File -->Save As… where the newly saved file should be named after the original image (without its extension, of course, with the added _Results.XLS. The creation of the Distribution chart works fine in my macro.

By the way, no parameters are being recorded or passed in Ridge Detection, which maybe is fine, since I often have to adjust them. Is it in principle possible, though?

Re the TIFF vs JPG exhortation, I do understand the general concern, but I have checked this dependency in my cases–and it doesn’t make any difference in the final results (in the end I process binary files with objects tens and hundreds of um long.)

More confusion though …

This Forum is for help but not to post orders!

All you need for re-naming files using the macro language is straightforward and described in the provided link or it can be recorded by the macro recorder. The remainder is performed by my macro.

no parameters are being recorded or passed in Ridge Detection

The “Ridge Detection”-plugin is fully macro recordable.

TIFF vs JPG […] it doesn’t make any difference in the final result.

This is simply not true and there are many examples that prove the opposite.

in the end I process binary files

After JPG-compression a binary image file is no longer binary, a fact that should convince you that JPG-compression changes image data.

This is a Forum dealing with scientific image processing; therefore approaches are to conform with rules of best practice.

Have a nice evening with enough drinks and more non-scientific fun.

Regards

Herbie

PS:
Special Xmas present:

nme=split(getTitle(), ".");
nme=nme[0]+"_Results.xls";
//
run("Ridge Detection", "…");
//
Table.rename("Summary", nme);
path=getDirectory("Where to save the results?");
saveAs("Results", path+nme);

Thank you, Herbie, for the Xmas present; I will not say a word more, other than that for people deep in a given field (here, image processing) it is often inconceivable that one may simply have no time nor inclination to learn the entire macro language (or JavaScript) to fix only one macro and, thus, for the sake of efficiency, one tends to rely on the kindness of others.

for people deep in a given field (here, image processing) it is often inconceivable that one may simply have no time nor inclination to learn the entire macro language

Aha, and those who are deep in their duties and businesses and nevertheless help?

Have a drink in your spare time for the well-being of those who invest time and effort in their spare time to provide help free of charge!

Herbie

Herbie, your expert help is greatly appreciated, and I mean it.

However, when I help others for free, I never begrudge their free time, because it takes away the pleasure of giving! :wink: