Home > InDesign Scripts > Extended undo/redo

Extended undo/redo

Are you frustrated with lack of History palette in InDesign? Did you know that you can retrieve undo/redo commands from script?😕 Yeah! That’s right! It’s really easy to achieve History palette functionality with some easy script. I created really simple dialog with two drop-down boxes and undo/redo buttons.😉 Let’s first how to get list of undo/redo commands that we have available.

To receive undo history we do this:

var docUndo = app.activeDocument.undoHistory;
var docRedo = app.activeDocument.redoHistory;

Received data is in Arrays, so if we want to see what we did for example 15 steps before, we do it like this:

var docUndo = app.activeDocument.undoHistory[14];

Don’t forget that Array starts from 0🙂

So, how we achieve undo/redo functionality? We list all undo/redo items in separate drop-down boxes, and when we click undo/redo, drop-down box gives us selection index, and then just simply loops app.activeDocument.undo(); or app.activeDocument.redo();.

Here is script that I built today:

var docUndo = app.activeDocument.undoHistory;
var docRedo = app.activeDocument.redoHistory;
if(!docUndo.length){
    var noUndo = Boolean(true);
    docUndo = Array("--- No Undo items ---");
}
if(!docRedo.length){
    var noRedo = Boolean(true);
    docRedo = Array("--- No Redo items ---");
}

var myUndoRedo = new Window('dialog', 'Extended Undo/Redo');
myUndoRedo.orientation = 'row';
with(myUndoRedo){
    myUndoRedo.undoPanel = add('panel', undefined, 'Undo');
    myUndoRedo.undoPanel.orientation = 'column';
    with(myUndoRedo.undoPanel){
        myUndoRedo.undoPanel.undoDrop = add('dropdownlist', undefined, undefined, {items:docUndo});
        myUndoRedo.undoPanel.undoDrop.selection = 0;
        myUndoRedo.undoPanel.btnUndo = add('button', undefined, 'Undo');
        myUndoRedo.undoPanel.btnUndo.onClick = function(){this.window.close(0);}
        }
    myUndoRedo.redoPanel = add('panel', undefined, 'Redo');
    myUndoRedo.redoPanel.orientation = 'column';
    if(noUndo)myUndoRedo.undoPanel.btnUndo.enabled = false;
    with(myUndoRedo.redoPanel){
        myUndoRedo.redoPanel.redoDrop = add('dropdownlist', undefined, undefined, {items:docRedo});
        myUndoRedo.redoPanel.redoDrop.selection = 0;
        myUndoRedo.redoPanel.btnRedo = add('button', undefined, 'Redo');
        myUndoRedo.redoPanel.btnRedo.onClick = function(){this.window.close(1);}
    }
    if(noRedo)myUndoRedo.redoPanel.btnRedo.enabled = false;
    myUndoRedo.infoGrp = add('group');
    myUndoRedo.infoGrp.alignment = 'bottom';
    myUndoRedo.infoGrp.orientation = 'column';
    with(myUndoRedo.infoGrp){
        myUndoRedo.infoGrp.btnCancel = add('button', undefined, 'Cancel');
    }
};

myUndoRedo.center();
myUndo = myUndoRedo.show();

if(myUndo == 0){
    var undoSteps = myUndoRedo.undoPanel.undoDrop.selection;
    for (var i = 0; i <= undoSteps; i++) {
        app.activeDocument.undo();
    }
}else if(myUndo == 1){
    var redoSteps = myUndoRedo.redoPanel.redoDrop.selection;
    for (var i = 0; i <= redoSteps; i++) {
        app.activeDocument.redo();
    }
}

Feel free to explore, change, and if you got better solution/idea just let me know😉

Have fun!😀

  1. July 30, 2010 at 22:24

    Hi Tomaxxi,
    A history script is available at Adobe Exchange😉
    http://bit.ly/cuK0E8
    Another at DTP but that’s a commercial one.

    • July 30, 2010 at 23:19

      Thanks Loic!
      But, as I can see, this is just for undo😉

  2. July 31, 2010 at 11:16

    You are so right.
    Vacations will be welcome🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: