Question

I need to check the number of assigned history states for Photoshop, as part of a script's start-up, to verify that the user has enough undo states set for the script to function properly. I could simply set the number of states with the code I got from the ScriptListener plugin, but I know some users of my scripts use more history states than I would set myself, via this code; so I'd like to simply verify they have the minimum required number of history states before the script will run, or pop a warning or auto-adjust after confirmation if they do not.

So in short, I'm looking for a way to get the currently set number of History (undo) States, in Photoshop, via scripting. Also, if anyone also knows a way to set that number (without using ScriptListener code), I would be interested in that as well (and will up-vote the first working version of that answer).

Was it helpful?

Solution

If you need to know the number of History states in the active document just use this script

var history_number = app.activeDocument.historyStates.length;
alert(history_number );

But if you need the main number of history states in the photoshop preferences use this one

var Hsstnum = app.preferences.numberOfHistoryStates;
alert (Hsstnum); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top