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

Is there a way to instantly revert any script to its original state?

Guide ,
Oct 27, 2025 Oct 27, 2025

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

TOPICS
Bug , How to , Scripting
94
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

Community Expert , Oct 28, 2025 Oct 28, 2025

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++
...
Translate
Community Expert ,
Oct 28, 2025 Oct 28, 2025

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).

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
Guide ,
Oct 28, 2025 Oct 28, 2025
LATEST

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.

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