How to retrieve all historyStates

Hey,
I am looking for a way to retrieve all historyStates. So far I have found only one variant with which I can retrieve the current historyState

Has anyone found a way?

In CEP I got it like this

app.activeDocument.historyStates

Thanks Joe

In the ActionDescriptor, you can target specific history states via any of the following:

  • _property: 'currentHistoryState'
  • _index: *index*
  • _name: *name*
  • _id: *id*

for example:

export function getHistoryState(_index?: number, _name?: string): HistoryState {
  return photoshop.action.batchPlay({
    _obj: 'get',
    _target: [
      {
        _ref: 'historyState',
        ...(!_index && !_name ? { _property: 'currentHistoryState'}: {}),
        ...(_index ? {_index} : {}),
        ...(_name ? {_name} : {})
      },
    ],
    _options: {
      dialogOptions: 'dontDisplay',
    },
  }, { synchronousExecution: true })[0]
}

Also, each HistoryStateDescriptor has a property called count, which is the total amount of history states in the document.

So in order to get all history states you’ll have to do:

  1. Get any history state (the active or at the first index, to be safe)
  2. Read out the count
  3. Get all history states by index in a loop (until you’ve reached count)

Important note: If I remember correctly, history states start at the itemIndex 1, and not at 0.

2 Likes

Thanks Simon,
a little more complicated than in CEP, but it works :smiley: