suspendHistory() equivalent for UXP in Photoshop?

Does anyone know if there is anything equivalent in UXP to the Extendscript suspendHistory()?

I’ve found it to be very useful because it speeds up the processing quite a bit. Also, consolidating history states into 1 is useful in many cases.

You can add the key ‘historyStateInfo’ to the batchplayOptions, which should include a name and target property, where the latter is an ActionReference, not a DOM-Element.

I personally use it like this:

function historyState(name: string) {
  return {
    name,
    target: {
      _ref: 'document',
      _enum: 'ordinal',
      _value: 'targetEnum',
    },
  }
}

function bpOptions(historyStateName: string) {
  return {
    ...(historyStateName ? { historyStateInfo: historyState(historyStateName)} : {}),
  }
}

require(photoshop).action.batchPlay([Desc1,Desc2,Desc3], bpOptions('Do some stuff'))
1 Like

Thanks for the info. I finally got a chance to look into the history states more it and test it out. For some reason, I couldn’t get it to work with your functions. I’m sure it was just my implementation of it.

However, based on what I can see it does and the info from the link you gave, I was able to piece it together and “dumb it down” to put it directly into the batchPlay options. Also, this way, I was also able to keep the synchronous option in batchPlay. In case it helps anyone else, here is the code for adding the History state directly to the batchPlay options. I still plan to play around with the functions you gave to see if I can make those work as I can see how they would be helpful. Honeslty, I’m not the most fluent person in javascript so dumbing it down like this helps for me to see it better though :slight_smile:

require("photoshop").action.batchPlay([duplicateLayer(), renameLayer("Test")], {
   
"synchronousExecution": true,
"modalBehavior": "fail",   
"historyStateInfo": {   
    "name": "History State Name Test",
    "_target": {
      "_ref": 'document',
      "_enum": 'ordinal',
      "_value": 'targetEnum',
    }
    },   
    
});    

function duplicateLayer() {
  return {
    "_obj": "copyToLayer",
    "_isCommand": true,
    "_options": {
      "dialogOptions": "dontDisplay"
    }
  }
}
    
function renameLayer(newName){
        
return   {
      "_obj": "set",
      "_target": [
         {
            "_ref": "layer",
            "_enum": "ordinal",
            "_value": "targetEnum"
         }
      ],
      "to": {
         "_obj": "layer",
         "name": newName
      },
      "_isCommand": false,
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }    
    
}

If you’re not using TypeScript, you have to remove the types from the code:
function historyState(name) instead of function historyState(name: string)

Maybe this was the issue.

Probably was, thanks :slight_smile:

Is there a way to suspend history outside of batchPlay?

I mean, if there are lots of stuff happening in a script using UXP API (DOM?), all of it gets logged to history. I have an ExtendScript which I’d like to refactor to UXP plugin command and which performs basically one action, but under the hood there are a lot of things happening and it wouldn’t even be possible to put everything into one batchPlay.