Copy link to clipboard
Copied
I have a recorded action where parts of it is running scripts in order to achieve what I need.
I now need a piece of script that will add the mask of the current layer to selection. I have tried and tried (with the help of Claude.ai 😁), but cannot get it to work. Can you help me?
As @c.pfaffenbichler writes, an action can do this. Record the action as follows.... With a selection active, hold down the shift key and the cmd or ctrl key and click on the layer mask with the mouse. Stop recording.
If you need ExtendScript code, then this should do the job:
if (hasLayerMask() == true) {
addLayerMaskSelToSel();
} else {
alert("The active layer doesn't have a raster layer mask!");
}
// c.pfaffenbichler from discussions with Mike Hale
function hasLayerM
...
Notice the difference in your action recording vs mine:
Record the action as follows:
Ensure that the layer with the mask is active/targeted/selected. With a selection active, hold down the Shift key and the Command or Ctrl key and click on the layer mask icon in the Layers panel with the mouse. Stop recording.
Copy link to clipboard
Copied
I assume things might improve but so far when people come to this Forum with ai-generated code it often appears to be pretty bad.
Could you please post screenshots taken at View > 100% with the pertinent Panels (Toolbar, Layers, Channels, Options Bar, …) visible to illustrate what exactly you are trying to automate?
As far as I can tell loading transparency as a Selection should work even in Actions as should loading the active Layer’s Layer Mask as a Selection.
Copy link to clipboard
Copied
I can get it to work with a recorded action, but then I have to manually press ok in this pop-up every time I run my action.
Copy link to clipboard
Copied
Notice the difference in your action recording vs mine:
Record the action as follows:
Ensure that the layer with the mask is active/targeted/selected. With a selection active, hold down the Shift key and the Command or Ctrl key and click on the layer mask icon in the Layers panel with the mouse. Stop recording.
Copy link to clipboard
Copied
Many thanks!
Copy link to clipboard
Copied
PS - do you know of a "good list" to use for all these shortcuts (where e.g. the shortcut works better than using the menues)? I use them so rarely so keep on forgetting that they exist.... 😊
Copy link to clipboard
Copied
PS - do you know of a "good list" to use for all these shortcuts (where e.g. the shortcut works better than using the menues)? I use them so rarely so keep on forgetting that they exist.... 😊
By @Chris201Chris
Offhand, no.
The Shift key is a commonly used modifier key used to continuously add to an existing selection, not just marching ant selections, but selecting multiple layers in the layers panel as another example.
The other common modifier keys are Option/Alt and Command/Ctrl on Mac or Win.
Copy link to clipboard
Copied
As @c.pfaffenbichler writes, an action can do this. Record the action as follows.... With a selection active, hold down the shift key and the cmd or ctrl key and click on the layer mask with the mouse. Stop recording.
If you need ExtendScript code, then this should do the job:
if (hasLayerMask() == true) {
addLayerMaskSelToSel();
} else {
alert("The active layer doesn't have a raster layer mask!");
}
// c.pfaffenbichler from discussions with Mike Hale
function hasLayerMask () {
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
return desc.hasKey(charIDToTypeID("UsrM"));
}
function addLayerMaskSelToSel() {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var reference = new ActionReference();
var reference2 = new ActionReference();
reference.putEnumerated( s2t( "channel" ), s2t( "ordinal" ), s2t( "targetEnum" ));
descriptor.putReference( s2t( "null" ), reference );
reference2.putProperty( s2t( "channel" ), s2t( "selection" ));
descriptor.putReference( s2t( "to" ), reference2 );
executeAction( s2t( "add" ), descriptor, DialogModes.NO );
}