Bug with batchPlay "Copy" command?

I’m getting the error “The Command “Copy” is not available”. I got this code directly from Alchemist. I’m not sure if the issue is with the generated code or if the issue is on the Photoshop side.

This should Select All and then Copy. I tried on a flattened image and also on a single layer image with a normal (not background) layer. In either case it gives the same message. It does do the Select All part. The copy command is available in the Photoshop menu. I also tried just the copy batchPlay command with a selection already made which gives the same message.

I would expect this error if the active layer was an adjustment layer or something that couldn’t be copied. but it is just a normal layer. I also tried using “cut” and it did the same thing.

If it is a bug in the Photoshop side then I will report the issue. However, I’m not sure if the bug is with Photoshop or with the generated code.

const batchPlay = require("photoshop").action.batchPlay;

const result = await batchPlay(
[
   {
      "_obj": "set",
      "_target": [
         {
            "_ref": "channel",
            "_property": "selection"
         }
      ],
      "to": {
         "_enum": "ordinal",
         "_value": "allEnum"
      },
      "_isCommand": false,
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   },
   {
      "_obj": "copyEvent",
      "_isCommand": false,
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }
],{
   "synchronousExecution": false,
   "modalBehavior": "fail"
});

Remove the _options key from the second descriptor, then it works.
Ps: don’t ask me why :sweat_smile:

OK, I just tried that. It doesn’t give the error anymore. But it also doesn’t copy the selection to the clipboard either. At least on my computer it doesn’t.

Remove the _isCommand thing too, from the second Descriptor. Seems like the copyEvent-Descriptor doesn’t pair well with additional keys

That works, thanks!

I will keep this in mind for other descriptors as well if I run into it again. Not much left in the descriptor :slight_smile:

   {
      "_obj": "copyEvent"
   }
1 Like

It’s nice to come across these minimalistic Descriptors every once in a while :blush:

Hi @simonhenke,
Can you give an insight on how you came across this tweak to the code to get it working? Is there some secret batchplay society I’m not aware of? :sunglasses:

I had the same error but I know next to nothing about batchplay so was stuck until I came across your post.

Thanks anyway,
John

@johnt When it comes to batchPlay, it always starts with some trial and error, but after some time you get used to it and learn more about the way it works and its properties.
The isCommand: true/false can generally be left out. It’s just for Photoshop to know which event to execute. Whenever some instance (e.g. a plugin) is actively listening for certain events, a copy of the Descriptor is “send out” with isCommand: false. So if you leave it out it should default to true.

I don’t know why the dialogOptions cause any problems, but they also don’t make a lot of sense in the context of a copy event as there’s no dialog involved. I’d recommend only inserting such properties when you’re actively trying to control the dialog behavior, not just put it into every descriptor for no reason.

After all, if you think about it, it makes sense that a copy event descriptor doesn’t need any additional payload / information.

1 Like

Thanks again @simonhenke. That makes sense :+1: