title: cropping multiple open documents in photoshop when making the first selection
body: <p>the script I am making should do this
  PDF-to psd (ok)
  all documents stays open (ok)
  the user make a selection what defines the crop for every open documents in Photoshop (not ok)
  close and save in an other folder(ok)</p>
  
  <p>The idea is that we have pdf's that we wound to crop in a certain way. But next time we will have other pdfs that has to be cropped in a different way. this what I 'have got so far but it's crops the documents like a set in the parameters.</p>
  
  <p>thanks</p>
  
  <pre><code> //PDFOpenOptions.jsx
          var OpenAIFile = new PDFOpenOptions;
          OpenAIFile.antiAlias = false;
          OpenAIFile.mode = OpenDocumentMode.CMYK;
          OpenAIFile.resolution = 150;
  
      var myFolder = Folder.selectDialog("select folder");
  
      if(myFolder != null)
      {
        var fileList = myFolder.getFiles(/\.(pdf)$/i);
        for(var i = 0 ;i &lt; fileList.length; i++)
        {
          if(fileList[i] instanceof File)
          {
            var doc= open(fileList[i],OpenAIFile);
          }
        }
      };
  
  var outputFolder = Folder.selectDialog("Dossier de destination:");
  
  //alert(outputFolder);
  
  if (app.documents.length &gt; 0) {
  //flatten the active document
  app.activeDocument.flatten();
  
  
  //jpeg options
  var myJPEGOptions = new JPEGSaveOptions();
  myJPEGOptions.embedColorProfile = true;
  myJPEGOptions.formatOptions = FormatOptions.STANDARDBASELINE;
  myJPEGOptions.matte = MatteType.WHITE;
  myJPEGOptions.quality = 12;
  myJPEGOptions.scans = 3;
  
  // get documents;
  var docs = app.documents;
  for (var m = 0; m &lt; app.documents.length; m++) {
  app.activeDocument = docs[m];
  
  try {
  
  //crop 1Lsquaire-got from script lisner
  var idCrop = charIDToTypeID( "Crop" );
  var desc4 = new ActionDescriptor();
  var idT = charIDToTypeID( "T   " );
      var desc5 = new ActionDescriptor();
      var idTop = charIDToTypeID( "Top " );
      var idPxl = charIDToTypeID( "#Pxl" );
      desc5.putUnitDouble( idTop, idPxl, 601.000000 );
      var idLeft = charIDToTypeID( "Left" );
      var idPxl = charIDToTypeID( "#Pxl" );
      desc5.putUnitDouble( idLeft, idPxl, 2068.000000 );
      var idBtom = charIDToTypeID( "Btom" );
      var idPxl = charIDToTypeID( "#Pxl" );
      desc5.putUnitDouble( idBtom, idPxl, 2948.000000 );
      var idRght = charIDToTypeID( "Rght" );
      var idPxl = charIDToTypeID( "#Pxl" );
      desc5.putUnitDouble( idRght, idPxl, 2918.000000 );
  var idRctn = charIDToTypeID( "Rctn" );
  desc4.putObject( idT, idRctn, desc5 );
  var idAngl = charIDToTypeID( "Angl" );
  var idAng = charIDToTypeID( "#Ang" );
  desc4.putUnitDouble( idAngl, idAng, 0.000000 );
  var idDlt = charIDToTypeID( "Dlt " );
  desc4.putBoolean( idDlt, false );
  var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );
  var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );
  var idtargetSize = stringIDToTypeID( "targetSize" );
  desc4.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idtargetSize );
  executeAction( idCrop, desc4, DialogModes.ALL );
  //crop 1Lsquaire
  
  
  //save file to folder
  var myFile = new File((outputFolder ) + "/" + activeDocument.name);
  app.activeDocument.saveAs(myFile, myJPEGOptions, true);
  
  }
  
  catch (e) {
  alert ("Error the script did not execute");
  }
  
  }
  
  while(documents.length&gt;0){
     documents[documents.length-1].close(SaveOptions.DONOTSAVECHANGES);
  }
  
  };
  </code></pre>