How to process image and output the plot profile in batch?

Hi, I’m very new to the imagej macro language, and I want to get .spe images in a folder and get the measurement plot values in a .csv file with the same name as the image, in the same folder. I tried a lot of ways but they all failed. here’s what I got so far.

extension = ".spe";
  dir1 = getDirectory("Choose Source Directory ");
  dir2 = getDirectory("Choose Destination Directory ");
  n = 0;

  function processFolder(dir1) {
     list = getFileList(dir1);
     for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
          else if (endsWith(list[i], extension))
             processImage(dir1, list[i]);

  function processImage(dir1, name) {
     makeLine(1, 640, 1200, 640);
     run("Plot Profile");
     saveAs(measurements, dir2+name+".csv");

could anyone help? thanks.

you can use the macro function getProfile() instead of run("Plot Profile"). The documentation at references an example that creates and saves a profile.