title: How to pass arguments within a function in imageJ macro?
body: <p>I want to pass in foldername into the run() function and the save() function but they are within quotes and I don't know how to pass the variable names.</p>
  
  <p>I generated the run() and save() function using the record command in imageJ.</p>
  
  <p>The aim of this program to to automate the process of running the plugin "T2 analysis mouse" on multiple folders. 
  Any other tweets or help will be appreciated. </p>
  
  <p>I found this online source <a href="https://imagej.nih.gov/ij/macros/ArgumentPassingDemo.txt" rel="nofollow noreferrer">https://imagej.nih.gov/ij/macros/ArgumentPassingDemo.txt</a> but it does not work.</p>
  
  <p>I tried multiple ways inclusing <code>/&amp;foldername/3 T2</code> <code>&amp;filename/3 T2</code> <code>/&amp;foldername 3 T2``/&amp;foldername3 T2</code> <code>/&amp;filename 3 T2``/&amp;filename3 T2</code>
  Here is the code I wrote:</p>
  
  <pre><code>function makeT2(foldername)
  {
      filename = foldername;
      print(filename);
      run("T2 Analysis mouse", "select=[/Users/Vineeth/Desktop/New stuff Feb 5/&amp;filename 3 T2] 
          image=[32-bit Signed] width=256 height=128 offset=0 number=902 gap=0 little-endian");
      run("Save", "save=[/Users/Vineeth/Desktop/New stuff Feb 5/&amp;foldername3 T2/T2map.tif]");
      close();
  }
  
  folders = getFileList("/Users/Vineeth/Desktop/New stuff Feb 5/");
  
  for( i = 0; i &lt; folders.length; i++)
  {
    print(folders[i]);
    file = getFileList("/Users/Vineeth/Desktop/New stuff Feb 5/" + folders[i]);
    for( j = 0; j &lt; file.length; j++)
    {
      if(file[j] == "3 T2/")
      {
        print("made t2 for  " + folders[i] + file[j]);
        makeT2(folders[i]);
  
      }
    }
  }
  </code></pre>
  
  <p>The various <code>print()</code> functions are for testing the code and the code mostly works expect for the makeT2 function.</p>
  
  <p>This is the error:</p>
  
  <pre><code>java.lang.NullPointerException
  at T2_Analysis_mouse.getImage(T2_Analysis_mouse.java:183)
  at T2_Analysis_mouse.run(T2_Analysis_mouse.java:56)
  at ij.IJ.runUserPlugIn(IJ.java:183)
  at ij.IJ.runPlugIn(IJ.java:150)
  at ij.Executer.runCommand(Executer.java:124)
  at ij.Executer.run(Executer.java:61)
  at ij.IJ.run(IJ.java:249)
  at ij.macro.Functions.doRun(Functions.java:561)
  at ij.macro.Functions.doFunction(Functions.java:79)
  at ij.macro.Interpreter.doStatement(Interpreter.java:203)
  at ij.macro.Interpreter.doBlock(Interpreter.java:518)
  at ij.macro.Interpreter.runUserFunction(Interpreter.java:278)
  at ij.macro.Interpreter.doStatement(Interpreter.java:206)
  at ij.macro.Interpreter.doBlock(Interpreter.java:518)
  at ij.macro.Interpreter.doStatement(Interpreter.java:239)
  at ij.macro.Interpreter.doIf(Interpreter.java:852)
  at ij.macro.Interpreter.doStatement(Interpreter.java:215)
  at ij.macro.Interpreter.doBlock(Interpreter.java:518)
  at ij.macro.Interpreter.doStatement(Interpreter.java:239)
  at ij.macro.Interpreter.doFor(Interpreter.java:464)
  at ij.macro.Interpreter.doStatement(Interpreter.java:221)
  at ij.macro.Interpreter.doBlock(Interpreter.java:518)
  at ij.macro.Interpreter.doStatement(Interpreter.java:239)
  at ij.macro.Interpreter.doFor(Interpreter.java:464)
  at ij.macro.Interpreter.doStatement(Interpreter.java:221)
  at ij.macro.Interpreter.doStatements(Interpreter.java:191)
  at ij.macro.Interpreter.run(Interpreter.java:102)
  at ij.macro.Interpreter.run(Interpreter.java:72)
  at ij.macro.MacroRunner.run(MacroRunner.java:124)
  at java.lang.Thread.run(Thread.java:695)
  </code></pre>
  
  <p>and this is the log after running the progran:</p>
  
  <pre><code>LeeMouseOld_30Jan18.LH1/
  made t2 for  LeeMouseOld_30Jan18.LH1/3 T2/
  LeeMouseOld_30Jan18.LH1/
  Please choose a directory where the T1 or T2 folder is the last item in the path (i.e. 5_t1 or 6_t2)
  Directory return for General T folder: /Users/Vineeth/Desktop/New stuff Feb 5/&amp;filename 3 T2/
  Please adjust import settings to:
  Image type: 32-bit signed
  Width: 128 pixels
  Height: 256 pixels
  Number of images: 50 images
  Check Little-endian byte order
  </code></pre>
  
  <p>As you can see <code>&amp;filename</code> remains the same but I want the data within the variable <code>filename</code> to be in its place. </p>