Skip to main content
Inspiring
June 24, 2018
Answered

Revert/Undo toggle

  • June 24, 2018
  • 3 replies
  • 3954 views

I would like to be able to toggle between the Revert and Undo commands in a script.

Is this type of toggle possible?

Ca the executeAction below return a boolean if  the Revert action is visible in the History Pallet?

//revert

executeAction( charIDToTypeID( "Rvrt" ), undefined, DialogModes.NO );

//step back 1 history state

var doc = activeDocument; 

doc.activeHistoryState = doc.historyStates[doc.historyStates.length-2];

This topic has been closed for replies.
Correct answer r-bin

Try this

if (activeDocument.activeHistoryState.snapshot)

    {

    var d = new ActionDescriptor();

    var r = new ActionReference();

    r.putEnumerated(stringIDToTypeID("historyState"), stringIDToTypeID("ordinal"), stringIDToTypeID("last"));

    d.putReference(stringIDToTypeID("null"), r);

    executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

    }

else

    {

    var d = new ActionDescriptor();

    var r = new ActionReference();

    r.putIndex(stringIDToTypeID("snapshotClass"), 1);

    d.putReference(stringIDToTypeID("null"), r);

    executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

    }

3 replies

r-binCorrect answer
Legend
June 24, 2018

Try this

if (activeDocument.activeHistoryState.snapshot)

    {

    var d = new ActionDescriptor();

    var r = new ActionReference();

    r.putEnumerated(stringIDToTypeID("historyState"), stringIDToTypeID("ordinal"), stringIDToTypeID("last"));

    d.putReference(stringIDToTypeID("null"), r);

    executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

    }

else

    {

    var d = new ActionDescriptor();

    var r = new ActionReference();

    r.putIndex(stringIDToTypeID("snapshotClass"), 1);

    d.putReference(stringIDToTypeID("null"), r);

    executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

    }

Inspiring
June 24, 2018

Thank you much, that accomplishes what I was looking for!

JJMack
Community Expert
Community Expert
June 24, 2018

Revert is not undo.  It is revert. If there is no DOM interface  I would think the scriptlistener would generate the code you need or an action where you insert a menu item File>revert.

You can also step back some number of history states and you can suspend history state recording in a script so you only need to step back one state to undo what the script did if you do not like what a script did.

Note: Last save version may not  you where you opened the document and that History state may NO longer exists. How many History states do you keep?

Revert to the last saved version

?Choose File > Revert.

Note: Revert is added as a history state in the History panel and can be undone.

JJMack
Geppetto Luis
Legend
June 24, 2018

I hope I have understood the question well

These are 2 scripts

one and to return history back

more to go history ahead

I put a shortcut button so I can use it quickly

story back

#target photoshop

// Step back

var docRef = app.activeDocument

var savedLayer = docRef.activeLayer

try{

var idslct = charIDToTypeID( "slct" );

    var desc3 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref1 = new ActionReference();

        var idHstS = charIDToTypeID( "HstS" );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idPrvs = charIDToTypeID( "Prvs" );

        ref1.putEnumerated( idHstS, idOrdn, idPrvs );

    desc3.putReference( idnull, ref1 );

    executeAction( idslct, desc3, DialogModes.NO );

}

catch(err)

{}

story ahead

#target photoshop

// Step forward

var docRef = app.activeDocument

var savedLayer = docRef.activeLayer

try{

    var idslct = charIDToTypeID( "slct" );

    var desc5 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref2 = new ActionReference();

        var idHstS = charIDToTypeID( "HstS" );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idNxt = charIDToTypeID( "Nxt " );

        ref2.putEnumerated( idHstS, idOrdn, idNxt );

    desc5.putReference( idnull, ref2 );

executeAction( idslct, desc5, DialogModes.NO );

}

catch(err)

{}

Inspiring
June 24, 2018

Thanks for helping answer my question. I am trying to find an efficient way to go from the current document history state back to the the original open history state and back to history current state. The idea is to be able to see the document without any edits and with the edits using a keyboard shortcut. I can do this manually by opening the History Pallet, selecting the document open state and then selecting the current history state. In short toggle between the two states with a script if it can be done with the history state.

Geppetto Luis
Legend
June 24, 2018