5 Replies Latest reply on Apr 14, 2013 12:34 PM by Michael L Hale

    Create a snapshot and return to snapshot, using Applescript?

    Mattmcquiff Level 1

      I'm just trying to create an applescript that will allow me to create a snapshot in my history and then later in the script select that history state/snapshot?

        • 1. Re: Create a snapshot and return to snapshot, using Applescript?
          Paul Riggott Level 6

          I think you will need to call a javaScript to do this...

           

           

          function createNamedSnapshot(name) {
              var desc = new ActionDescriptor();
                  var ref = new ActionReference();
                  ref.putClass( charIDToTypeID('SnpS') );
              desc.putReference( charIDToTypeID('null'), ref );
                  var ref1 = new ActionReference();
                  ref1.putProperty( charIDToTypeID('HstS'), charIDToTypeID('CrnH') );
              desc.putReference( cTID('From'), ref1 );
              desc.putString( charIDToTypeID('Nm  '), name );
              desc.putEnumerated( charIDToTypeID('Usng'), charIDToTypeID('HstS'), charIDToTypeID('FllD') );
              executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );
          };
          function revertNamedSnapshot(name) {
              var desc = new ActionDescriptor();
                  var ref = new ActionReference();
                  ref.putName( charIDToTypeID('SnpS'), name );
              desc.putReference( charIDToTypeID('null'), ref );
              executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
          };
          
          
          • 2. Re: Create a snapshot and return to snapshot, using Applescript?
            Muppet Mark Level 5

            You should be able to do this using the DOM in AppleScript or JavaScript…

             

            tell application "Adobe Photoshop CS5"

                      tell the current document

                                set hS to current history state

              change mode to Lab -- do whatever your stuff is…

                                set current history state to hS

                      end tell

            end tell

             

            var doc = app.activeDocument;

             

            var hS = doc.activeHistoryState;

             

            doc.changeMode( ChangeMode.LAB );

             

            app.refresh();

             

            doc.activeHistoryState = hS;


             


            • 3. Re: Create a snapshot and return to snapshot, using Applescript?
              Michael L Hale Level 5

              I think snapshots are better as you don't have to worry about the number of steps the script creates between setting and restoring. There is a chance that the number of steps in the script pushes the stored historyState off the panel and you can't restore later.

              • 4. Re: Create a snapshot and return to snapshot, using Applescript?
                Muppet Mark Level 5

                I don't doubt you Mike… and Paul's action manager can be called by either… So no problems there… I was just making the point that document history is a standard scriptable feature of the app…

                • 5. Re: Create a snapshot and return to snapshot, using Applescript?
                  Michael L Hale Level 5

                  I was just making the point that document history is a standard scriptable feature of the app…

                  Yes, it is. And I wasn't trying to say one shouldn't use it. I use them when there are only one or two steps in the script between setting and restoring.

                   

                  Between historyStates, snapshots, and suspendHistory() we don't have to worry as much as we once did about a script wiping out the user's history.