Answered
delete the last three history state
welcome everybody
- I want a code that deletes the last three history state

welcome everybody
- I want a code that deletes the last three history state

Try the following code, it has not been exhaustively tested, however, it would appear to do what you have requested:
/*
Delete The Last 3 History States.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/delete-the-last-three-history-state/td-p/14022026
v1.0 - 21st August 2023, Stephen Marsh
*/
#target photoshop
var theStateLength = activeDocument.historyStates.length - 1;
if (theStateLength >= 4) {
// Perform the tasks 3 times
for (i = 0; i < 3; i++) {
// Select the last history step
activeDocument.activeHistoryState = activeDocument.historyStates[activeDocument.historyStates.length - 1];
// Delete the active history step
removeHistoryStep();
}
alert("The last 3 history states have been deleted!")
} else {
alert("Script cancelled as there are only 3 or less history states!")
}
function removeHistoryStep() {
function s2t(s) {
return app.stringIDToTypeID(s);
}
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putProperty(s2t("historyState"), s2t("currentHistoryState"));
descriptor.putReference(s2t("null"), reference);
executeAction(s2t("delete"), descriptor, DialogModes.NO);
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.