Copy link to clipboard
Copied
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];
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
Copy link to clipboard
Copied
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)
{}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
see and this is good for you
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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()
Copy link to clipboard
Copied
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];
Copy link to clipboard
Copied
Thanks for the clarification. Is it possible to script a toggle function using either DOM or Action Manger code for Revert and Undo?
Copy link to clipboard
Copied
For instance is it possible to check if the Revert action is present in the history pallet?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
Thank you much, that accomplishes what I was looking for!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now