Copying A Selection Driving Me Nuts

After manually making a selection the whole routine is supposed to something like this…

Copy the selection and paste inplace to another document.
It seems to be falling over at the first step on Windows.

Any help on this would be very welcome.

const batchPlay = require("photoshop").action.batchPlay;
   const result = await batchPlay(
   [
      
      {
         "_obj": "copyEvent",
         "copyHint": "pixels",
         "_isCommand": true,
         "_options": {
            "dialogOptions": "dontDisplay"
         }
      }
   ],{
      "synchronousExecution": false,
      "modalBehavior": "fail"
   });

Screenshot 2021-07-19 150637

"_options": {
  "dialogOptions": "dontDisplay"
}

seems to be the problem here. If you remove it, the alert doesn’t pop up.

That does remove the alert but it doesnt appear to copy anything because under the Edit Menu, Paste is Disabled

Do you have some non-transparent pixels when you copy?

No I dont. I even filled the whole document with black and it still doesnt copy anything.

I dont have my Mac here at the moment so unable to confirm it its just a Windows issue

I’m a bit confused :slight_smile: So you don’t have non-transparent pixels? Or you do have? Because you mentioned all black :slight_smile: My guess was, that nothing is copied if all pixels are transparent

What I mean is that I have even created a new document, filled it with Black, made a selection with the Lasso Tool and tried to copy that selection and still nothing appears to get copied

No idea why, but it appears to be working now.

Thanks for everyones input.

I spoke to soon :frowning:
It works perfect on the MAC but just not on Windows.

Did you find a solution??

I can’t make it work and it is driving me nuts too!

I’m on windows 11 btw

I found the solution and it works fine now on Windows 11

This was the code I was using before, same as you:

async function copyPixels() {
  try {
    await batchPlay([
      {
        "_obj": "copyEvent",
        "_isCommand": true,
        "_options": {
          "dialogOptions": "dontDisplay"
        }
      }
    ], {});
  } catch (e) {
    console.log(e);
  }
}

Seems that if you remove this key and its value, the function works fine:

"_isCommand": true,

It should be something like this:

async function copyPixels() {
  try {
    await batchPlay([
      {
        "_obj": "copyEvent",
        "_options": {
          "dialogOptions": "dontDisplay"
        }
      }
    ], {});
    // console.log('here');
  } catch (e) {
    console.log(e);
  }
}

I’m testing it right now and it seems works fine. Hope it works for you as well.

Again, I’m on Windows 11.

EDIT:

I also noticed that this works aswell:

async function copyPixels() {
  try {
    await batchPlay([
      {
        "_obj": "copyEvent"
        }
      }
    ], {});
    // console.log('here');
  } catch (e) {
    console.log(e);
  }
}

Kind regards,

Whoa, thanks so much for this suggestion on removing “_isCommand”: true,

But… why, though?! Why does this make the action work?

1 Like