# How to retrieve all historyStates

**URL:** <https://forums.creativeclouddeveloper.com/t/how-to-retrieve-all-historystates/2635>\
**Category:** Photoshop\
**Created:** [March 10, 2021, 1:43pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-retrieve-all-historystates/2635 "2021-03-10T13:43:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/joe/32/1246_2.png) [@Joe](https://forums.creativeclouddeveloper.com/u/Joe)\
**Post date:** [March 10, 2021, 1:43pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-retrieve-all-historystates/2635/1 "2021-03-10T13:43:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)\
**Post date:** [March 10, 2021, 3:48pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-retrieve-all-historystates/2635/2 "2021-03-10T15:48:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Joe](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/joe/32/1246_2.png) [@Joe](https://forums.creativeclouddeveloper.com/u/Joe)\
**Post date:** [March 10, 2021, 4:33pm UTC](https://forums.creativeclouddeveloper.com/t/how-to-retrieve-all-historystates/2635/3 "2021-03-10T16:33:50Z")

</div>

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