API 2 Trouble playing actions from action set

I’m in the process of learning a lot of the UXP Documentation. Using @DavideBarranca new “UXP plugins developement with React JS”. I had some code working that would play an action from an action set in API 1. When I upgraded to the PS 2022, my practice plug in wouldn’t load and stated that I had to switch to API 2. Now in API 2 the following code will no longer play the action.

const doAction = async (actionset, action) => {
console.log(actionset, action);
photoshop.app.actionTree
.find(({name}) => name === actionset)
.actions
.find(({name}) => name === action)
.play()
}
When I tried logging the promise associated with play() it said it was rejected:

  • Promise {[[PromiseState]]: “pending”, [[PromiseResult]]: undefined}
  1. proto: Promise
  2. [[PromiseState]]: “rejected”
  3. [[PromiseResult]]: Error: Event: play may modify the state of Photoshop. Such events are only allowed from inside a modal scope

So I tried using executeAsModal and got it to play the action:

const executeAsModal = require(“photoshop”).core.executeAsModal;
const doAction = async (actionset, action) => { await executeAsModal(async () => {
console.log(actionset, action);
await photoshop.app.actionTree
.find(({name}) => name === actionset)
.actions
.find(({name}) => name === action)
.play()
})
}

The issue I am having now is that every dialog box that may be associated with a given step with in the action pops up forcing the user to click ok on each rather than running the action without user input.

Is there a way to suppress these dialog boxes and run the action all the way through without user input/confirmation?

Interesting, just to be clear you’re saying that with API 2 each action basically has all steps toggled on, i.e. with dialogs—à la DialogModes.ALL in old ActionManager syntax, so to speak?

I’ve just tried in the Console with a dummy action (Export as), but it doesn’t trigger the dialog, everything goes fine:

Instead if I check the mark right on the left of the “Export” in the Action palette, the dialog pops up:

I’m on a Mac, are you by any chance on Windows?

Davide

@DavideBarranca Thank you! it was as simple as that. When I upgraded to PS 2022 it must have toggled all those dialogs on. Then I was struggling to even get the actions to run in API 2 until I figured out the executeAsModal method. I am about half way through your UXP course. Will you be updating some of the plug in examples to API 2 now that API 1 is deprecated in PS2022?

Thanks again for all of your content!

1 Like

You’re welcome!
Actually I’m already working on the first round of fixes, which will be API 2 compliance for the examples that used API 1 and also I’m updating screenshots of the UXP Developer Tool, which new version has been released like one week after I’ve published the course :sweat_smile:Nothing substantially different, but I like to be up-to-date!

1 Like