Skip to main content
Participant
August 26, 2016
Answered

Undoing in scripts

  • August 26, 2016
  • 2 replies
  • 3241 views

How to get effect of "ctrl + z" combination in script? Why do I need it? I need one image in a lot of sizes, so I want to resize it, save, restore to default, resize again etc. in loop (sizes are in array). I prefer not to close and reopen the same image. Thanks in advance and sorry for my english.

This topic has been closed for replies.
Correct answer pixxxelschubser

Hi joffrey​,

try this

executeAction( charIDToTypeID('undo'), undefined, DialogModes.NO );

This line should toggle same as [Strg]+

Have fun

2 replies

MarkWalsh
Inspiring
August 27, 2016

The proper way to do this would be to save the document's current history state before you alter the document, then restore it afterwards. I'm on my iPhone right now so I don't have access to the script that I have for creating multiple images which use this, but this should be what you need:

var savedHistoryState = app.activeDocument.activeHistoryState

// create first image

app.activeDocument.activeHistoryState =  savedHistoryState

// create second image

app.activeDocument.activeHistoryState =  savedHistoryState

// etc

Known Participant
January 24, 2017

Thanks Mark, i found your method to be the best solution for my script.

JJMack
Community Expert
Community Expert
July 27, 2018

The other easy way to do what you want is duplicate document with newname for file resize save and close. No undo or backup in history is needed.  When all  sizes have been save close the document or end the script and continue processing the document.

JJMack
pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
August 26, 2016

Hi joffrey​,

try this

executeAction( charIDToTypeID('undo'), undefined, DialogModes.NO );

This line should toggle same as [Strg]+

Have fun

joffreyAuthor
Participant
August 26, 2016

Well, it is the correct answer and thank you very much for this. Thanks to this, I noticed, that I need "step backward" function, but this time I've found the answer here: http://superuser.com/questions/19878/photoshop-enable-multiple-undo (I don't need to save active layer, so I used only part of it).

Thank you once again.

pixxxelschubser
Community Expert
Community Expert
August 26, 2016

Glad I could help.

If you need a Javascript solution for [strg]+[alt]+ try this function

// by Michael L. Hale

//For the menu item 'Step Backward' ( the same as alt-ctrl-z ) use this

function stepHistoryBack(){

    var desc = new ActionDescriptor();

        var ref = new ActionReference();

        ref.putEnumerated( charIDToTypeID( "HstS" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Prvs" ));

    desc.putReference(charIDToTypeID( "null" ), ref);

executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

};

Have fun