2 Replies Latest reply on Jun 28, 2010 7:33 AM by Ghoulfool

    Bad script, no biscuit!

    Ghoulfool Level 1

      I've just cut and paste a script from the script listener - which I mage minor edits to. The script basically copies part of an image, scales it down and saves it out as a png. It works fine locally on my machine (and fine over our network). However when I tried it on a collegues maxchine it barfed at either closing the pngs or the next step which is switching back to the source document. I suspect it could be the latter - not finding previous document.

       

      I haven't pasted the whole script as it quite long, but this is the area where it runs into problems.

       

      // =======================================================
      var id633 = charIDToTypeID( "Cls " );
      executeAction( id633, undefined, DialogModes.NO );

       

      // =======================================================
      // select me
      var id135 = charIDToTypeID( "slct" );
          var desc39 = new ActionDescriptor();
          var id136 = charIDToTypeID( "null" );
              var ref14 = new ActionReference();
              var id137 = charIDToTypeID( "Dcmn" );
              ref14.putOffset( id137, -1 );
          desc39.putReference( id136, ref14 );
      executeAction( id135, desc39, DialogModes.NO );

       


      // =======================================================
      var id634 = charIDToTypeID( "setd" );
          var desc134 = new ActionDescriptor();
          var id635 = charIDToTypeID( "null" );
              var ref86 = new ActionReference();
              var id636 = charIDToTypeID( "Chnl" );
              var id637 = charIDToTypeID( "fsel" );
              ref86.putProperty( id636, id637 );
          desc134.putReference( id635, ref86 );
          var id638 = charIDToTypeID( "T   " );
          var id639 = charIDToTypeID( "Ordn" );
          var id640 = charIDToTypeID( "None" );
          desc134.putEnumerated( id638, id639, id640 );
      executeAction( id634, desc134, DialogModes.NO );

       

      // image coffee

       

      // =======================================================
      var id513 = charIDToTypeID( "slct" );
          var desc110 = new ActionDescriptor();
          var id514 = charIDToTypeID( "null" );
              var ref72 = new ActionReference();
              var id515 = charIDToTypeID( "Lyr " );
              ref72.putName( id515, "Background" );
          desc110.putReference( id514, ref72 );
          var id516 = charIDToTypeID( "MkVs" );
          desc110.putBoolean( id516, false );
      executeAction( id513, desc110, DialogModes.NO );

       

      // =======================================================

       

      Can anyone think the script would be fine on my machine and yet fail on  another?

        • 1. Re: Bad script, no biscuit!
          Michael L Hale Level 5

          I see two things that might throw an error. Not because it is running on a different machine but for other reasons.

           

          If the document has been changed since it was opened your close code will throw an error. Try

              var desc = new ActionDescriptor();
              desc.putEnumerated( charIDToTypeID( "Svng" ), charIDToTypeID( "YsN " ), charIDToTypeID( "N   " ) );
          executeAction( charIDToTypeID( "Cls " ), desc, DialogModes.NO );
          
          // or use the DOM
          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
          

          The last step you posted selects the background. If the document does not have a background that will also throw an error.

          1 person found this helpful
          • 2. Re: Bad script, no biscuit!
            Ghoulfool Level 1

            Thank you Michael, I've altered that code and now it works properly.