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'))
2 Likes

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.

I have this problem too. My UXP plugin (panel) has sliders that I want to update the layer in real-time as the user adjusts the slider. This is easy to do with BatchPlay but each change is logged to the history and it isn’t long until the history is flooded with each change of the slider.

I’ve gotten some limited success by doing a complex lookup in the history panel to see if the previous state is a slider adjustment and delete it before making the change, but this just adds extra complexity to an already system-intensive process. Unfortunately it doesn’t look like you can delete the current history state without undoing it (which is dumb, in my opinion!)

There is a parameter in the “historyStateInfo” object called “suppressHistoryStateNotification” that you’re SUPPOSED to be able to set to “true” in your BatchPlay object, but it doesn’t do anything right now…not sure if it’s a bug or just hasn’t been implemented or??? Also in the “historyStateInfo” object is a “coalesce” flag which is SUPPOSED to collapse all similarly-named history states into one state (similar to what happens when you “nudge” a layer with your keyboard while the Move tool is selected)…but, of course, this doesn’t work either. Again, no idea if it’s a bug or not implemented or what???

I’m REALLY trying to get on board with UXP…but it’s is SUPER frustrating to work with if you want to create anything useful or cool. They put out these examples that are like: “oooh, look what you can do with UXP” but they don’t really do anything useful and NONE of them interact with Photoshop.

Does anyone have any useful tips to pass along for doing real-time slider updates?