3 Replies Latest reply on Apr 13, 2011 3:57 PM by Michael L Hale

    Create History snap replacing an existing one

    DBarranca Level 4


      I've written this function using Scripting Listener code and XTools, which saves an History snapshot:


      // fist param string, second boolean
      function CreateSnapshot(name, merged) {
        function cTID(s) { return app.charIDToTypeID(s); };
        function sTID(s) { return app.stringIDToTypeID(s); };
      var myMerged = (merged == true) ? 'Mrg2' : 'FllD';
      var undefined = charIDToTypeID( "Mk  " );
          var desc29 = new ActionDescriptor();
              var ref26 = new ActionReference();
              ref26.putClass( cTID('SnpS') );
          desc29.putReference( cTID('null'), ref26 );
              var ref27 = new ActionReference();
              ref27.putProperty( cTID('HstS'), cTID('CrnH') );
          desc29.putReference( cTID('From'), ref27 );
          desc29.putString( cTID('Nm  '), name );
          desc29.putEnumerated( cTID('Usng'), cTID('HstS'), cTID(myMerged) );
          desc29.putBoolean( sTID('replaceExisting'), true ); // to remove in order to make it work more than once
          executeAction( undefined, desc29, DialogModes.NO );


      Basically, the next to last commented line should instruct PS to replace an existing snap with the very same name - and doesn't work, and throws "General PS error - this functionality may not be available" etc.

      Strangely enough, if I run the original ScriptingListener code (and not my rearranged function):


      var idMk = charIDToTypeID( "Mk  " );
          var desc79 = new ActionDescriptor();
          var idnull = charIDToTypeID( "null" );
              var ref83 = new ActionReference();
              var idSnpS = charIDToTypeID( "SnpS" );
              ref83.putClass( idSnpS );
          desc79.putReference( idnull, ref83 );
          var idFrom = charIDToTypeID( "From" );
              var ref84 = new ActionReference();
              var idHstS = charIDToTypeID( "HstS" );
              var idCrnH = charIDToTypeID( "CrnH" );
              ref84.putProperty( idHstS, idCrnH );
          desc79.putReference( idFrom, ref84 );
          var idNm = charIDToTypeID( "Nm  " );
          desc79.putString( idNm, "TEST" );
          var idUsng = charIDToTypeID( "Usng" );
          var idHstS = charIDToTypeID( "HstS" );
          var idFllD = charIDToTypeID( "FllD" );
          desc79.putEnumerated( idUsng, idHstS, idFllD );
          var idreplaceExisting = stringIDToTypeID( "replaceExisting" );
          desc79.putBoolean( idreplaceExisting, true );
      executeAction( idMk, desc79, DialogModes.NO );


      I get the same behavior (it works when there's no previously existing snap with the same name, it throws the error otherwise).

      Am I missing something?


      Thanks in advance,



        • 1. Re: Create History snap replacing an existing one
          Michael L Hale Level 5

          At a guess it is because you have undefined as the frist argument for executeAction. It should be charIDToTypeID( "Mk  " )

          • 2. Re: Create History snap replacing an existing one
            DBarranca Level 4

            Hi Mike,

            the "undefined" variable comes from fixing the SL code with Xtools - on the other hand even the raw SL code throws the error - and works flawlessy if there's no any snap that shares the same name.

            What's strange to me is: how could a SL code coming from registering one particular move (ALT + click in the new Snap icon in the History palette, inserting the name, and clicking Yes to the "Replace?" question) do not work?




            • 3. Re: Create History snap replacing an existing one
              Michael L Hale Level 5

              Yes, sorry I didn't read the post fully. undefined is a special word in ExtendScript. Although you can redefine it like you have done here I think it would be better to choose a different variable name, something like var eventID = charIDToTypeID( "Mk  " );


              But I see what you mean about it not working if a historyState with that name already exists. All I can think of is that Photoshop does something that is not recorded by scriptlistner when the 'Replace Snapshot "TEST"?' dialog appears.


              What is even stranger is it works as an action but the javascript created with xtools from that action does not. Nor do I see anything in the xml from the atn file that is created by xtools that is not in the javascript.