How to restore historyState

I get actionDescriptor in Alchemist which is

const batchPlay = require("photoshop").action.batchPlay;

const result = await batchPlay(
[
   {
      _obj: "historyStateChanged",
      documentID: 342,
      ID: 352,
      name: "demo-2.psd",
      hasEnglish: false,
      itemIndex: 0,
      _options: {
         dialogOptions: "dontDisplay"
      }
   }
],{
   synchronousExecution: false,
   modalBehavior: "fail"
});

when I use it in photoshop 2022, it does not work. What is wrong?

I don’t think historyStateChanged is something you can actively execute via batchPlay, it’s more of a notification event.
If your intention was to restore the document state to a previous one, you should select a history state instead:

{
   "_obj": "select",
   "_target": [
      {
         "_ref": "historyState",
         "_offset": -2
      }
   ]
}

This would go back 2 steps, but you can also reference historyStates by ID (_id) instead of _offset

1 Like

You could also do something like:

const doc = app.activeDocument;
const hist = doc.historyStates;
doc.activeHistoryState = hist[hist.length - 2]

https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes/historystate/
https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes/document/#properties-1
https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes/historystates/

1 Like