# Is it possible to make UndoModes.ENTIRE\_SCRIPT when executing UXPScript in doScript?

**URL:** <https://forums.creativeclouddeveloper.com/t/is-it-possible-to-make-undomodes-entire-script-when-executing-uxpscript-in-doscript/9047>\
**Category:** InDesign\
**Tags:** uxp, javascript\
**Created:** [January 15, 2025, 7:14am UTC](https://forums.creativeclouddeveloper.com/t/is-it-possible-to-make-undomodes-entire-script-when-executing-uxpscript-in-doscript/9047 "2025-01-15T07:14:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sttk3](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sttk3](https://forums.creativeclouddeveloper.com/u/sttk3)\
**Post date:** [January 15, 2025, 7:14am UTC](https://forums.creativeclouddeveloper.com/t/is-it-possible-to-make-undomodes-entire-script-when-executing-uxpscript-in-doscript/9047/1 "2025-01-15T07:14:48Z")

</div>

When executing a UXP script from ExtendScript or AppleScript via doScript (do script), the behavior always seems to be UndoModes.SCRIPT\_REQUEST even if any UndoModes are specified.

This means that the changes made by the script cannot be reverted in a single Undo, but must be repeated for each step Undo.

How to make this an ENTIRE\_SCRIPT behavior, where the changes made by the script can be reverted in a single Undo?

### Sample code

```auto
// ExtendScript

var uxpCode = '''
const { app } = require('indesign') ;
const sel = app.activeDocument.selection[0] ;
sel.move([0, 0]) ;
sel.move([0, 100]) ;
''' ;

try {
  app.doScript(uxpCode, ScriptLanguage.UXPSCRIPT, [], UndoModes.ENTIRE_SCRIPT) ;
} catch(e) {
  alert(e) ;
}

```

```auto
-- AppleScript

tell application id "com.adobe.InDesign"
	set uxp_code to "
const { app } = require('indesign') ;
const sel = app.activeDocument.selection[0] ;
sel.move([0, 0]) ;
sel.move([0, 100]) ;
"
	do script uxp_code language uxpscript with arguments {} undo mode entire script
end tell

```

---

<div class="post-metadata">

**Author:** ![Dirk](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@Dirk](https://forums.creativeclouddeveloper.com/u/Dirk)\
**Post date:** [February 6, 2025, 1:27pm UTC](https://forums.creativeclouddeveloper.com/t/is-it-possible-to-make-undomodes-entire-script-when-executing-uxpscript-in-doscript/9047/2 "2025-02-06T13:27:50Z")

</div>

Some ideas:

- add an undoName string as argument after the undoMode.
- make sure your UXP script considers [global await](https://developer.adobe.com/indesign/uxp/scripts/concepts/global-await/).
- wrap your doScript to invoke UXPSCRIPT in a function, which you invoke in another doScript that stays in ExtendScript and is responsible for the undoMode.

---

<div class="post-metadata">

**Author:** ![sttk3](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sttk3](https://forums.creativeclouddeveloper.com/u/sttk3)\
**Post date:** [February 7, 2025, 3:39am UTC](https://forums.creativeclouddeveloper.com/t/is-it-possible-to-make-undomodes-entire-script-when-executing-uxpscript-in-doscript/9047/3 "2025-02-07T03:39:22Z")

</div>

Thank you for your response. Tried all of them and to no success.  
The following code is an example that is awkward but includes all the requirements.

```auto

(function() {
  var scriptCode = '''
const { app } = require('indesign') ;
const doSomething = async () => {
  const sel = app.activeDocument.selection[0] ;
  await sel.move([0, 0]) ;
  await sel.move([0, 100]) ;
} ;
await doSomething() ;
''' ;

  try {
    app.doScript(doUXPScript.toSource() + '("""' + scriptCode + '""");', ScriptLanguage.JAVASCRIPT, [], UndoModes.ENTIRE_SCRIPT, 'doJavaScript') ;
  } catch(e) {
    alert(e) ;
  }
})() ;

function doUXPScript(argv) {
  app.doScript(argv, ScriptLanguage.UXPSCRIPT, [], UndoModes.ENTIRE_SCRIPT, 'doUXPScript') ;
}

```

---

<div class="post-metadata">

**Author:** ![Dirk](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@Dirk](https://forums.creativeclouddeveloper.com/u/Dirk)\
**Post date:** [February 9, 2025, 10:56am UTC](https://forums.creativeclouddeveloper.com/t/is-it-possible-to-make-undomodes-entire-script-when-executing-uxpscript-in-doscript/9047/4 "2025-02-09T10:56:17Z")

</div>

This works for me:

```auto
function main()
{
	try {
		app.doScript('''
			const { app } = require('indesign') ;
			const sel = app.activeDocument.selection[0];
			sel.move([0,0]);
			sel.move([0,100]);
		''',ScriptLanguage.UXPSCRIPT);
	} catch(e) {
		alert(e);
	}
}

app.doScript(
	main,
	ScriptLanguage.JAVASCRIPT,
	[],
	UndoModes.ENTIRE_SCRIPT,
	"Single Step"
);

```

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/e/ea2c4260aa94f83ee0b44fa1e7863649c5b98740.png)  
The image shows the “Protokoll” panel (German locale) manual steps of

- delete the protocol “Löschen”
- create a new object
- running the script - all changes merged into “Single Step”

The Undo menu also has “Rückgängig: Single Step”

---

<div class="post-metadata">

**Author:** ![sttk3](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sttk3](https://forums.creativeclouddeveloper.com/u/sttk3)\
**Post date:** [February 9, 2025, 12:46pm UTC](https://forums.creativeclouddeveloper.com/t/is-it-possible-to-make-undomodes-entire-script-when-executing-uxpscript-in-doscript/9047/5 "2025-02-09T12:46:53Z")

</div>

Thank you, succeeded with your format. I modified the code in the UXPScript to be variables, as follows.

```auto
(function() {
  var uxpCode = '''
const { app } = require('indesign') ;
const { script } = require('uxp') ;
const sel = app.activeDocument.selection[0] ;
sel.move([0,0]) ;
sel.move([0,100]) ;
script.setResult('Result from UXPScript') ;
''' ;

  var res = app.doScript(doUXPScript, ScriptLanguage.JAVASCRIPT, [uxpCode], UndoModes.ENTIRE_SCRIPT, 'Single Step') ;
  alert(res) ;
})() ;

/**
  * Execute UXP script, must do via doScript, pass target code as arguments
  * @returns {Any} 
*/
function doUXPScript() {
  return app.doScript(arguments[0].toString(), ScriptLanguage.UXPSCRIPT) ;
}

```
