Copy link to clipboard
Copied
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+
...
Copy link to clipboard
Copied
DOM appears to offer no Methods for HistoryState so please record the operation with ScriptingListener.plugin yourself.
Copy link to clipboard
Copied
Aha ok sir
You mean that there is no direct command to delete history satate
Is this what you mean sir??
I found this code works to set the last history state
How can I delete the last specified record
var doc = app.activeDocument;
doc.activeHistoryState = doc.historyStates[doc.historyStates.length-1];
Copy link to clipboard
Copied
I found this code works to set the last history state
How can I delete the last specified recordvar doc = app.activeDocument; doc.activeHistoryState = doc.historyStates[doc.historyStates.length-1];
That code does not delete a HistoryState it selects one (makes it the active one).
Aha ok sir
You mean that there is no direct command to delete history satate
Is this what you mean sir??
I mean you should use ScriptingListener.plusing to record deleting the last HistoryState.
Copy link to clipboard
Copied
That code does not delete a HistoryState it selects one (makes it the active one).
Well I know it selects one
But how to delete history when it is activated
There is a way to delete this record
Copy link to clipboard
Copied
I have already told you to use ScriptingListener.plugin to record the operation twice.
Is there a problem with this?
https://helpx.adobe.com/photoshop/kb/downloadable-plugins-and-content.html
Copy link to clipboard
Copied
Sorry bro, I don't know what is the difference between script code
and ScriptingListener. plugin
Or how can I write a line for this
Copy link to clipboard
Copied
Please don’t bother asking questions but install ScriptingListener.plugin and use it to record the code for the operation already. (Edit: If the recorded code does not perform as expected then please post it with a clear explanation what happens/fails to happen.)
I won’t try to explain the difference between Photoshop’s DOM- and AM-code now.
Copy link to clipboard
Copied
Very sorry to disturb you
Well, I will do as you tell me
Thank you for your interest and sorry again for the inconvenience sir
Copy link to clipboard
Copied
You can download the plug-in here:
https://helpx.adobe.com/au/photoshop/kb/downloadable-plugins-and-content.html
You should get something like the following to delete the active history state:
var iddelete = stringIDToTypeID( "delete" );
var desc57 = new ActionDescriptor();
var idnull = stringIDToTypeID( "null" );
var ref4 = new ActionReference();
var idhistoryState = stringIDToTypeID( "historyState" );
var idcurrentHistoryState = stringIDToTypeID( "currentHistoryState" );
ref4.putProperty( idhistoryState, idcurrentHistoryState );
desc57.putReference( idnull, ref4 );
executeAction( iddelete, desc57, DialogModes.NO );
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
Thank you very much for your help
The code has already worked very well
Thank you again sir
Copy link to clipboard
Copied
You're welcome, and it was constructive that you did post the code to select the last snapshot, it shows that you are at least trying.