List of batchPlay commands?

Hi, I’m new to this batchPlay command.
Almost every command I got was from this forum and Alchemist
But where exactly those commands from? Like:

const exportCommand = {
  _obj: "exportSelectionAsFileTypePressed",
  _target: { _ref: "layer", _enum: "ordinal", _value: "targetEnum" },
  fileType: "png",
  quality: 8,
  metadata: 0,
  destFolder: outputFolder, //destFolder.nativePath,
  sRGB: true,
  openWindow: false,
  _options: { dialogOptions: "dontDisplay" },
};
//
await core.executeAsModal(
  async () => {
    await action.batchPlay([exportCommand], {
      modalBehavior: "execute",
      synchronousExecution: false,
    });
  },
  { commandName: `Export Layer As PNG start` }
);

Where did they even find this? Not in the docs either.
The closest thing I can find is this website with 6000 Photoshop events.
But just the name doesn’t do anything…
Photoshop StringID-TypeID-CharID List – Automation Skill (ten-artai.com)

Any help is appreciated, cause Idk anymore.

I get almost all my batchPlay from Alchemist also. You can also get it from “Copy as Javascript” in the Photoshop actions fly-out menu to convert actions to batchPlay.

I don’t think many UXP developers (except for maybe some at Adobe) write it from scratch. I’ve also not seen a comprehensive catalog of batchPlay code. That said, sometimes people have parameters for it that I don’t know where they got it either.

1 Like

The technology underlying batchPlay (Action Descriptor?) seems to have maintained a similar structure for quite a long time. Thus, the following resources may be of interest to you.

In addition, official Photoshop features may have been developed using technologies such as ExtendScript, CEP, and UXP.

Thanks for helping.
But nope, even with those I just need to use Alchemist to get the batchPlay code instead because the output is mostly the same. So ExtendScript looks like a joke to me (because I can’t understand it)
And I just want to achieve what antipalindrome/Photoshop-Export-Layers-to-Files-Fast: This script allows you to export your layers as individual files at a speed much faster than the built-in script from Adobe. (github.com) does
Basically on the export section. But can’t even find a way to Export Individual Layer yet.

According to the link you provided, PNG24 is saved as export and PNG8 is saved as save for web. This part is translatable to batchPlay because it uses Action Descriptor instead of ExtendScript commands.

Both use syntaxes like new File(path), which is the type that UXP basically blocks. With the right permissions and getEntryWithUrl it might be possible to achieve this.

It seems to limit export to one layer by showing the target layer and hiding the other layers.

I saw some old plugin does that or maybe Photoshop itself does it back to idk 2,4,6 years ago?
This is the worked batchPlay code I got and modified the path a bit so It can export all the layers with prefix and groups as folders…

I’ve to add a 100ms delay in for … of loop so it can be done. Faster than the script in the link I provided ( Which creates a new document and idk…)

Idk, why it didn’t work yesterday but now It seems to work.

And does the .jsx script in the link? Does it ExtendScript or Action Descriptor? Is it similar to the UXP Plugins? Thank you for helping!!

await core.executeAsModal(
  async () => {
    const selectCommand = {
      _obj: "select",
      _target: [
        {
          _ref: "layer",
          _id: layer.id,
        },
      ],
      makeVisible: false,
      layerID: [layer.id],
      _isCommand: false,
    };

    const exportCommand = {
      _obj: "exportSelectionAsFileTypePressed",
      _target: {
        _ref: "layer",
        _enum: "ordinal",
        _value: "targetEnum",
      },
      fileType: "png",
      quality: 32,
      metadata: 0,
      destFolder: outputPath, //destFolder.nativePath,
      sRGB: true,
      openWindow: false,
      _options: { dialogOptions: "dontDisplay" },
    };
    await action.batchPlay([selectCommand, exportCommand], {
      modalBehavior: "execute",
      synchronousExecution: false,
    });
  },
  { commandName: `Export Layer As PNG` }
);

Glad it worked out.

The script jsx in the link you provided is ExtendScript. However, it uses Action Descriptor for some of the processing, such as exporting.

The Action Descriptor used in ExtendScript is superficially different from the one used in the UXP Plugin’s batchPlay, but essentially the same. This means that they can be cross-translated.

1 Like

You are right. I re-read the code again and seems like it does copy to the new document, select the exporting layer and hide others then use the saveAs function for duplicate documents close it then repeat. It seems like the code is similar so I can look up the document https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes

Doing that seems like it opens another ability to do more with the layer like scale, padding… or more export file types.

But I just want to export it as png and it already trimmed the layer so it’s fine for me now. Thank you!

1 Like