I have been experiencing strange issues with the InDesign history after running some of my scripts (AppleScript or JavaScript).

Specifically I have created a floating palette using ScriptUI in JavaScript that contains a list of icon buttons, that when clicked runs an AppleScript, using doScript. This is an example of the code:

Running an AppleScript from JavaScript.

app.doScript(File('the_script.scpt'), ScriptLanguage.applescriptLanguage, ["argument_1","argument_2"], UndoModes.fastEntireScript);

Since the AppleScripts are performing a lot of actions, and I only want to save all these actions as one single "undo", I apply UndoModes.fastEntireScript to the doScript.

When I have run this script just once, the undo history of the InDesign document in general is changed. When working normally and undoing once, it will undo the last many steps and not just one step as usual.

What is the problem here? Does changing the UndoMode for a single script execution change the documents UndoMode as well? Is it a bug, or just an user error - what can I do to prevent it?