title: Photoshop Script - worked fine if/when dragged and dropped to run, returned error when added to Scripts. Now won't even function on a fresh install
body: <p>I'm often required to stitch together a lot of images with subtle transitions or repetitive patterns, but loading them all into Photomerge and running in a single go was prone to a whole slew of issues (poor alignment, complete omission of images, etc) so I found the best way to go about it was to break it down and run the merge on two images at a time &gt; save them &gt; next two &gt; save them &gt; etc until all images had been paired ..and then the process again on those combined sets to create larger combined sets.. and again and again until only one file remained. Painfully time consuming when the files are 80MP and 16bit tiff, but I did find a batch stitch solution which would combine anything within each respective subfolder of a target folder.</p>
  <p>I then hired someone to create a script based on this which would basically do that elimination for me: 12 files in a folder would be paired off and stitched (AB CD EF GH IJ KL) and then it would run it again (ABCD EFGH IJKL) and again (ABCDEFGH IJKL) until only one file remained (ABCDEFGHIJKL). They supplied it with photomerge.jsx and I was instructed to drag/drop into PS, select the target folder, and let it do its thing. And it worked perfectly.</p>
  <p>But then I tried to move the script into the scripts menu in PS. Didn't work. Replaced the photomerge.jsx that was in PS with the one supplied - and that didn't work either. Restored the original photomerge.jsx and tried running the script via drag and drop as originally instructed: no luck. Uninstalled PS, reinstalled, tried original functioning script - and the same error is returned.</p>
  <blockquote>
  <pre class="lang-none prettyprint-override"><code>Error 2: folder is undefined. 
  -&gt; errorLog = errorLog.concat(decodeURI(folder));
  </code></pre>
  </blockquote>
  <p>From the way that I've seen the script work, two folders (test folder 1, test folder 2) are created within the sub folder and the merges take place in there. The script appears to get through the first merge before crapping out.</p>
  <p>The respective section is here:</p>
  <pre class="lang-js prettyprint-override"><code>///merges all files in [fList] and saves the result in [saveLoc]
  ///the result is every 2 couple images are merged together in [saveLoc]
  function photomergeAllFilesAsCouples(fList,saveLoc)
  {
      //divide the list into equal sized couple lists
      var subLists = divideIntoSubCouples(fList)
      for(var si = 0; si &lt; subLists.length;si++)
      {
          var subList = subLists[si];
          try 
          {
              // The Photomerge generates an unsaved new document with layers
              if(TEST_MODE)
                  open(subList[0])
              else
                  photomerge.createPanorama(subList, false);
                  
              try{
                  if(!TEST_MODE) activeDocument.mergeVisibleLayers();
              } catch(e) {}
          
              var resultFileName = RemoveExtension(subList[0].displayName) + RemoveExtension(subList[1].displayName);
              if(TEST_MODE)
                  SaveJPG(saveLoc,resultFileName,1);
              else
                  SaveTIFF(saveLoc,resultFileName);
  
              // close the document without saving 
              activeDocument.close(SaveOptions.DONOTSAVECHANGES);
  
              // if we've reached this point without hitting an error then the child folder is considered properly stitched
              numberOfGood = numberOfGood+1;
          } catch (e) {
              errorLog = errorLog.concat(&quot;\nUndetermined error on &quot;);
              errorLog = errorLog.concat(decodeURI(folder));
              errorLog = errorLog.concat(&quot; &quot;);
          } // end catch
      } 
  }
  </code></pre>
  <p>Would anyone be able to advise where this is going so horribly wrong?</p>