Skip to main content
Participant
January 8, 2015
Question

AIS CC: how undoing the actions of a JS run via app.doScript

  • January 8, 2015
  • 1 reply
  • 761 views

Hello,

AIS CC (9.0)

I wrote a JavaScript, which I can properly run through app.doScript(UndoModes.fastEntireScript, etc.).

Now, at a given time, I would like to programmatically undo the actions of my own script.

The various resources I have got here (InDesign_ScriptingGuide_JS (CS6), InDesign_ScriptingTutorial, the ExtendScript Toolkit Object Model browser) suggest things (app.undo(), app.documents.item(0).undo(), etc.) which fail, when executed on my AIS CC.

Any idea or tip, on how to undo actions submitted via doScript on AIS CC?

Thanks in advance!

Kind regards,

GB

Snippet:

var main = function()

{

     // something

}

app.doScript(

     main,

     ScriptLanguage.javascript,

     undefined,

     UndoModes.fastEntireScript

     ); // << this works perfectly: the actions in the "main" function are executed

app.undo(); // << this will fail with "app.undo is not a function"

This topic has been closed for replies.

1 reply

TᴀW
Legend
January 8, 2015

Well, you're in a bind -- because you've wrapped everything up in a

fastEntireScript, that effectively makes the entire script a single undo

step. So when you call app.undo(), you're undoing the entire script,

which is probably not what you want.

Incidentally, fastEntireScript used to be very buggy -- the

recommendation is to us entireScript. Not sure if that was fixed for the

latest version.

Anyway, the only idea I have is to nest what you need to undo in a

UndoModes.SCRIPT_REQUEST. Perhaps that way you will be able to undo that

step individually.

You may want to reconsider why your script needs to undo anything

anyway. It sounds an inefficient way to write a script, although I can

see that for a quick one-off it may be the simplest way of doing some

things.

id-extras.com | InDesign tools & scripts for typesetters, form designers, and translators
Participant
January 8, 2015

Thanks for your fast reply.

you're undoing the entire script, which is probably not what you want.

Undoing everything embedded in my "main" function is really what I want to achieve.

Whether it's a bunch of complex code, or nothing at all (as in my snippet, where "main" contains only a comment line ), it's what I want.

the recommendation is to us entireScript

I changed my "UndoModes.fastEntireScript" into "UndoModes.entireScript", as you suggested; with no avail so far: I still get the same "is not a function" error.

Actually, I have the feeling that I do not understand/master the InDesign DOM here, and am simply trying to make a call to a method (undo) which does not exist in this class (app) - despite the Adobe Reference Manual says it does...

It sounds an inefficient way to write a script

My script makes some changes in an InDesign document ("main" function), then exports it to PDF (out of the "main" function).

Then, the environment I work with (XMPie) will inject variable information in the InDesign document for the next recipient.

At this time, I need the document to be reset to its original design.

That's why I need to undo all the changes applied by the "main" function.

TᴀW
Legend
January 8, 2015

try

app.activeDocument.undo()

instead.

id-extras.com | InDesign tools & scripts for typesetters, form designers, and translators