When running a script within UndoMode.AUTO_UNDO, ID will add the script's undo to the previous undo item on the undo stack. If there is no previous undo item on the stack, it appears that you will not be able to undo your script's action.
For example, after you manually create a new rectangle, Edit > Undo displays "Undo Add New Item".
If you then run script (while in auto undo mode) that turns off the visibiltiy of a layer, Edit > Undo will still display "Undo Add New Item"--even after your script has run.
If you do the Edit > Undo ("Undo Add New Item") after your script has run, not only will the creation of the new rectangle be undone, so will your layer settings. The undo for the layer settings will happen along with the previously created undo.
Here's a script that you can run after you create a new rectangle (or whatever) and see how it does not affect the top item of the undo stack after it is run. After running the script below, you will see that the script's changes are undone with along with the previous undo.
// Make sure the frontmost doc has a layer named, "Layer 1" before running this script. app.doScript(ChangeLayerFunc, ScriptLanguage.javascript, undefined, UndoModes.AUTO_UNDO, undefined); function ChangeLayerFunc() { app.activeDocument.layers.item("Layer 1").visible = false; }
I hope this helps!
-- Jim
www.premediasystems.com