Copy link to clipboard
Copied
Some scripts can be undone with a single click before execution.
But for others, you have to roll back step by step.
Some scripts perform multiple operations, making it cumbersome to revert to the state before execution.
Is there a way to undo these multi-step scripts with one click, returning them to their origina
Hi @dublove, yes in most cases it is possible. Just make sure you call your script using app.doScript and pass it UndoModes.ENTIRE_SCRIPT.
For example, this is my code on a question you posted previously:
function main() {
var doc = app.activeDocument;
var items = doc.selection;
// must update `items` with new item references
items = setItemStackingOrder(doc, items, sortByLeftTop);
// just for testing final order, print the names
for (var i = 0; i < items.length; i++...
Copy link to clipboard
Copied
Hi @dublove, yes in most cases it is possible. Just make sure you call your script using app.doScript and pass it UndoModes.ENTIRE_SCRIPT.
For example, this is my code on a question you posted previously:
function main() {
var doc = app.activeDocument;
var items = doc.selection;
// must update `items` with new item references
items = setItemStackingOrder(doc, items, sortByLeftTop);
// just for testing final order, print the names
for (var i = 0; i < items.length; i++) {
$.writeln(i + ': item ' + items[i].name);
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Stacking Order');
In fact, you you will see this on every script I have ever posted for you lol 🙂
- Mark
EDIT (for extra info): What we are doing is calling the `main` function using the app.doScript call. So any code you put in the `main` function will execute, even if it just calls another function. You don't have to use `main`—name it whatever you want. You can still use other functions as normal, so long as they are in scope (visible to the `main` function, for example).
Copy link to clipboard
Copied
What? Oh my gosh.
I almost deleted all the app.doScript( ) files.
I've always wondered why it was such a hassle...
Turns out it has a clever use after all.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now