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

Revert/Undo toggle

Engaged ,
Jun 24, 2018 Jun 24, 2018

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

TOPICS
Actions and scripting
3.9K
Translate
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

People's Champ , Jun 24, 2018 Jun 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.putRefe

...
Translate
Adobe
Advocate ,
Jun 24, 2018 Jun 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)

{}

Translate
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
Engaged ,
Jun 24, 2018 Jun 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.

Translate
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
Advocate ,
Jun 24, 2018 Jun 24, 2018
Translate
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 ,
Jun 24, 2018 Jun 24, 2018

How many history states have you set in your Photoshop preferences The list is just so long. When the list is full old states start falling off the list. The list requires resources and can effect Photoshop's performance.

JJMack
Translate
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
Engaged ,
Jun 24, 2018 Jun 24, 2018

I have 50 history states. I check the file by going File > Revert which adds the action as a history state and then Cmd+ Z to undo.

It would useful to have to be able to do this action with keyboard short cut. I am able to capture both of these commands with the script listener. I am failing creating the toggle action tho. I don't undertstand the DOM.

function revert() {

  // =======================================================

  var idinvokeCommand = stringIDToTypeID( "invokeCommand" );

      var desc133 = new ActionDescriptor();

      var idcommandID = stringIDToTypeID( "commandID" );

      desc133.putInteger( idcommandID, 34 );

      var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );

      desc133.putBoolean( idkcanDispatchWhileModal, true );

  executeAction( idinvokeCommand, desc133, DialogModes.NO );

  // =======================================================

  var idRvrt = charIDToTypeID( "Rvrt" );

  executeAction( idRvrt, undefined, DialogModes.NO ); 

}

function undo() {

  // =======================================================

  var idinvokeCommand = stringIDToTypeID( "invokeCommand" );

      var desc134 = new ActionDescriptor();

      var idcommandID = stringIDToTypeID( "commandID" );

      desc134.putInteger( idcommandID, 101 );

      var idkcanDispatchWhileModal = stringIDToTypeID( "kcanDispatchWhileModal" );

      desc134.putBoolean( idkcanDispatchWhileModal, true );

  executeAction( idinvokeCommand, desc134, DialogModes.NO ); 

}

revert ();

//undo()

Translate
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 ,
Jun 24, 2018 Jun 24, 2018

None of what you show here is Adobe DOM(Document Object Model) Photoshop Script Code.  All code you see here is Action Manager Code note all the "executeAction( ..... ); " functions.

Scriptlistener records Action manager code  not Adobe DOM Photoshop script code.

Your first append has some DOM code

//step back 1 history state

var doc = activeDocument;

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

https://wwwimages2.adobe.com/content/dam/acom/en/devnet/photoshop/pdfs/photoshop-cc-scripting-guide-...

https://wwwimages2.adobe.com/content/dam/acom/en/devnet/photoshop/pdfs/photoshop-cc-javascript-ref-2...

JJMack
Translate
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
Engaged ,
Jun 24, 2018 Jun 24, 2018

Thanks for the clarification. Is it possible to script a toggle function using either DOM or Action Manger code for Revert and Undo?

Translate
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
Engaged ,
Jun 24, 2018 Jun 24, 2018

For instance is it possible to check if the Revert action is present in the history pallet?

Screen Shot 2018-06-24 at 12.48.44 PM.png

Translate
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 ,
Jun 24, 2018 Jun 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
Translate
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
People's Champ ,
Jun 24, 2018 Jun 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);

    }

Translate
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
Engaged ,
Jun 24, 2018 Jun 24, 2018
LATEST

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

Translate
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