The command “<unknown>” is not currently available

Hi folks, as per Title, i’m running into this error while launching a script via a test panel i’m doing.

The command “” is not currently available.

Any hint what this means?

{
      _obj: "invokeCommand",
      commandID: 1900,
      kcanDispatchWhileModal: true,
      _options: {
         dialogOptions: "dontDisplay"
      }
   }

The panel is simply creating a new layer via copy and it’s applying “Calculations”, than it’s going to channels and it’s selecting the new channel.

What do you mean by that? If JSX, then it’s not supported in UXP

It’s part of a code extracted from Alchemist. It works but it stops with this error.

Which menu item 1900 command points to? Is this item enabled when you try to run the script? Sounds like for some reason this command is not available at the time, but to confirm would require a bit more info

It’s calling the “Calculations” menu.

I don’t know why BP fails with that message, but maybe you could get away with this?

    require("photoshop").core.performMenuCommand({
        commandId: 1900
    })

Menu commands are risky, I’m pretty sure that Calculations leaves a proper trace in Alchemist.
Apply Image and Calculations may appear in DOM in the next months, though.

The following code worked for me

await core.performMenuCommand({commandID: 1900, kcanDispatchWhileModal: true, _isCommand: false});

There are times that the menu item for Calculations is grayed out, like when a Group layer is the active layer, so make sure that isn’t the situation when the command gets called.

Also, this would need to be called inside executeAsModal.

I use calculations in my plugin and have my own function for it, it creates a newChannel and applies calculations into this new channel, returning the new channel name which normally is “Alpha 1”. I only use two Alphas so that’s why I have it hard coded, but you can change it at your own necessity.

Mind that I have the “if else” statement because doing caldulations with RGB channels is a different batchplay command than doing calculations with custom channels.

async function doCalculations(a, b, blend) {
  try {
    console.log(a);
    if (a == "Alpha 1" || a == "Alpha 2") {
      await batchPlay([
        {
          "_obj": "make",
          "new": {
            "_class": "channel"
          },
          "using": {
            "_obj": "calculation",
            "to": {
              "_ref": "channel",
              "_name": a
            },
            "calculation": {
              "_enum": "calculationType",
              "_value": blend
            },
            "source2": {
              "_ref": "channel",
              "_enum": "channel",
              "_value": b
            }
          },
          "_isCommand": true
        }
      ], {});
    } else {
      await batchPlay([
        {
          "_obj": "make",
          "new": {
            "_class": "channel"
          },
          "using": {
            "_obj": "calculation",
            "to": {
              "_ref": "channel",
              "_enum": "channel",
              "_value": a
            },
            "calculation": {
              "_enum": "calculationType",
              "_value": blend
            },
            "source2": {
              "_ref": "channel",
              "_enum": "channel",
              "_value": b
            }
          },
          "_isCommand": true
        }
      ], {});
    }
    const channel = app.activeDocument.channels[app.activeDocument.channels.length - 1].name;
    return channel;

  } catch (e) {
    console.log(e);
  }
}

The function takes three arguments, the channelA, channelB and the blendingMode. This function also returns the name of the new channel that was created with the calculations on it.

Hope it is helpful for you.