I would recommend keeping this page bookmarked to use, it has the built-in macro functions of ImageJ and explains what they do, sometimes with examples.
To get the name of the image you can use
getTitle(); to get the header name (this usually has the file extension at the end, if the image was only just opened). To get the file name without the extension you can replace the string of the file extension (e.g. “.tif”) with nothing. Example:
replace(imgTitle, ".tif", "");. Or if the image is the last file opened, you can use
Once you have this variable set (let’s call it
filename), you can save the results table using
saveAs("Results", dir + filename + ".csv"); where
dir is the directory you want to save the .csv files in. You can use
dir = getDirectory("Choose directory for saving"); to assign the variable, this opens a pop-up window so you can choose a directory.
Batch processing information can be found on this webpage, so you can apply your script to all of your files. Alternatively you can use the batch processing plugin (Process > Batch > Macro…).