Skip to main content
Mike.Kominek
Participating Frequently
February 1, 2021
Answered

PS JavaScript how to paste into an alpha channel

  • February 1, 2021
  • 2 replies
  • 904 views

Hello,

 

I am trying to paste my current clipboard contents into a specific alpha channel.

say named "Alpha 6"

The document is likely to have your normal RGB + a number of alpha channels so I need to paste the contents into a specific one.

Doing it by hand works perfectly, no idea how to achieve it via script.

I already have quite a complex java script written that does a lot of things, this is just a extention of it I am trying to do and I just cant figure this bit out. So I do need to use Java for this.

 

Thanks for any help

This topic has been closed for replies.
Correct answer Stephen Marsh

For the clipboard to alpha, you can use this function:

 

 

function clipboardToAlpha(alphaName) {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putName( s2t( "channel" ), alphaName );
	descriptor.putReference( c2t( "null" ), reference );
	executeAction( s2t( "select" ), descriptor, DialogModes.NO );
	descriptor2.putEnumerated( c2t( "AntA" ), s2t( "antiAliasType" ), s2t( "antiAliasNone" ));
	descriptor2.putClass( s2t( "as" ), s2t( "pixel" ));
	executeAction( s2t( "paste" ), descriptor2, DialogModes.NO );
}

 

 

Then call the function with the required alpha channel name as a parameter in double quotes:

 

 

clipboardToAlpha("Alpha 6"); // Alpha channel name

 

 

2 replies

Stephen Marsh
Stephen MarshCorrect answer
Community Expert
February 1, 2021

For the clipboard to alpha, you can use this function:

 

 

function clipboardToAlpha(alphaName) {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putName( s2t( "channel" ), alphaName );
	descriptor.putReference( c2t( "null" ), reference );
	executeAction( s2t( "select" ), descriptor, DialogModes.NO );
	descriptor2.putEnumerated( c2t( "AntA" ), s2t( "antiAliasType" ), s2t( "antiAliasNone" ));
	descriptor2.putClass( s2t( "as" ), s2t( "pixel" ));
	executeAction( s2t( "paste" ), descriptor2, DialogModes.NO );
}

 

 

Then call the function with the required alpha channel name as a parameter in double quotes:

 

 

clipboardToAlpha("Alpha 6"); // Alpha channel name

 

 

Mike.Kominek
Participating Frequently
February 2, 2021

This worked perfectly, thank you!

Mike.Kominek
Participating Frequently
February 1, 2021

Or if there is a way to copy a LayerSet that is not necesarily on top in the document, into a alpha channel without the use of clipboard, that would be even more optimal. Thank you

Stephen Marsh
Community Expert
February 1, 2021

Can you share a screenshot of your layers panel with the targeted layer group/set expanded and visible?