Adding Unit to Filename


I am trying to save my results with a custom filename. I figured out how to get filename from photo and replace “.tif” with “.csv”.
But my current challenge is using the data of unit. Because each SEM photo I use have different units (µm or nm). I manually enter this data while I set the scale but I do not know how I can get this info and use on filename part of my macro code.

My current macro code for it this:

//saving the file
name = getTitle;
            dotIndex = indexOf(name, ".tif");
            title = substring(name, 0, dotIndex); 
saveAs("Results", "/Users/macbook/Desktop/"+title+".csv");

At the end I need the filenames like that [title+um or nm]
Screenshot 2021-01-23 at 23.29.48

Can anybody help me on this?

Thanks a lot in advance!


Maybe this?

newImage("Machin", "RGB white", 256, 256, 1);
makeLine(44, 185, 160, 187);
run("Set Scale...", "distance=116.0172 known=1 unit=mm");
   title = getTitle;
  getPixelSize(unit, pw, ph, pd);
  print("Title: " + title);
// saveAs( "C:/.....................your folder name................../"+title+"_"+unit+".png");

Reading this may interest you: getPixelSize(unit, pixelWidth, pixelHeight)


Hey @Mathew thanks for your comment.
I failed on that part getPixelSize(unit, pw, ph, pd);

Now my current code is like that and works as I wish,

name = getTitle;
            dotIndex = indexOf(name, ".tif");
            title = substring(name, 0, dotIndex); 
getPixelSize(unit, pw, ph, pd);
saveAs("Results", "/Users/macbook/Desktop/"+title"+"_"+unit+".csv");

Thanks lot!