Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
1

delete the last three history state

Enthusiast ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

welcome everybody

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

Untitled-1.jpg

 

TOPICS
Actions and scripting , SDK

Views

570
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 20, 2023 Aug 20, 2023

@Mohamed Hameed 

 

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+
...

Votes

Translate
Adobe
Community Expert ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

DOM appears to offer no Methods for HistoryState so please record the operation with ScriptingListener.plugin yourself. 

Screenshot 2023-08-20 at 17.59.00.png

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

@c.pfaffenbichler 

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]; 

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

quote

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]; 

That code does not delete a HistoryState it selects one (makes it the active one). 

 

quote

@c.pfaffenbichler 

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.  

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

quote

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

 

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2023 Aug 20, 2023

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

@c.pfaffenbichler 

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2023 Aug 20, 2023

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. 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

@c.pfaffenbichler

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

@Mohamed Hameed 

 

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 );

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

@Mohamed Hameed 

 

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);
}

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

@Stephen Marsh 

Thank you very much for your help
The code has already worked very well
Thank you again sir

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2023 Aug 20, 2023

Copy link to clipboard

Copied

LATEST

@Mohamed Hameed 

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines