Is there a way to Copy channel, duplicate, paste channel into new layer? For UXP Plugin?

I am trying to create a UXP plugin that
1: duplicates a channel,
2: make selection and copy that new channel,
3. switch back to RGB channels,
4 create new layer
4. past into the new layer
So far in 24.7.0 the UXP script can get to duplicate channel and select but can not copy selection of a channel and paste it to a new layer. You can do this in a action and jsx file but when it comes to UXP no luck. Can anyone figure out how it can work?

What I am trying to do is use a channel as a selection and then copy and paste it into a new RGB layer. Anyone have a solution?

Certain functionalities are currently unavailable within the DOM, but you can use batchPlay for now. If you’re just starting out with UXP, you could record these steps into an action. Afterward, navigate to Photoshop Preferences > Plugins > Enable Developer Mode. Within the action panel, select your recorded action, on the action’s drop-down menu, click on “Copy as JavaScript.” You can use that code in your plugin and to learn how the UXP environment works. cheers

Thats great but somethings are still not available to put into a UXP environment. Like for example: In my action I duplicate the blue channel, make a selection of that channel go back to the RGB channels and copy the background layer with the selection. A simple paste on new layer will still not work. I wish I can get this to work.

Running tests, it might work!

If all you want (I might getting it wrong, though) is to paste a channel into a new layer, why don’t you use ApplyImage()?

let res = await executeAsModal(async () => {
    const doc = app.activeDocument;
    const lay = await doc.createPixelLayer();
        source: { 
            document: doc, 
            layer: constants.ApplyImageLayer.MERGED,
            channel: doc.channels[0]

}, { commandName: "baa" })

It’s documented here.
Hope this helps,


Thank you, I think I have an idea that will work, just testing in.