Skip to main content
_wckdTall_
Inspiring
October 21, 2026
Answered

When I run a script is there a way to get it to have the undo stay on the same page?

The normal behavior I encounter after running a script on an entire document, is that hitting undo jumps to whatever page I ran the script from.

Just now, running the same script and hitting undo kept me on the same page I was currently looking at, so I could toggle back and forth to see changes to multiple pages. This is PREFERRED for some of my scripts and edits within InDesign is there a way to toggle this on and off? Closing InDesign and reopening a document restored Behavior 1 on the same document the only thing I can think is the prior session the file had crashed, and opened a temp version.

 

Behavior 1:
Page 1 → run → Page 2 → Undo → Page 1

Behavior 2:
Page 1 → run → Page 2 → Undo → stays Page 2

    rob day
    rob dayCorrect answer
    Community Expert
    October 21, 2026

    Behavior 2:
    Page 1 → run → Page 2 → Undo → stays Page 2

     

    Hi ​@_wckdTall_ , You should be able to do it using the SCRIPT_REQUEST UndoMode. So, with an 8 page doc active with rulers set to Inches:

     


    //The doScript function to run
    function main(){
    //active doc page 5
    var ap = app.activeDocument.pages[4]
    //go to page 4
    app.activeWindow.activePage = ap
    //run makeFrame function to create a black text frame function
    makeFrame(ap)
    }


    //Make a black textframe at page p
    function makeFrame(p){
    p.textFrames.add ({geometricBounds: [0,0,4,4], fillColor: "Black"});
    }

    //undo the main function with SCRIPT_REQUEST UndoMode—removes the black frame and stays on page 4
    app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.SCRIPT_REQUEST, 'Make Black Frame');

     

     

    https://www.indesignjs.de/indesignapi/indesign/UndoModes.html

    1 reply

    rob day
    Community Expert
    rob dayCommunity ExpertCorrect answer
    Community Expert
    October 21, 2026

    Behavior 2:
    Page 1 → run → Page 2 → Undo → stays Page 2

     

    Hi ​@_wckdTall_ , You should be able to do it using the SCRIPT_REQUEST UndoMode. So, with an 8 page doc active with rulers set to Inches:

     


    //The doScript function to run
    function main(){
    //active doc page 5
    var ap = app.activeDocument.pages[4]
    //go to page 4
    app.activeWindow.activePage = ap
    //run makeFrame function to create a black text frame function
    makeFrame(ap)
    }


    //Make a black textframe at page p
    function makeFrame(p){
    p.textFrames.add ({geometricBounds: [0,0,4,4], fillColor: "Black"});
    }

    //undo the main function with SCRIPT_REQUEST UndoMode—removes the black frame and stays on page 4
    app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.SCRIPT_REQUEST, 'Make Black Frame');

     

     

    https://www.indesignjs.de/indesignapi/indesign/UndoModes.html

    Translate