@nickcombs thanks for contributing... For me, your code is still flagging a single transparent layer with no content as not having transparency.
Thanks for catching that @Stephen Marsh. I have updated the code below with a layer_is_empty function to handle that special case.
// https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-check-if-a-layer-contains-any-transparent-pixels/td-p/9917339
alert( "Layer is " +( layer_is_solid() ? "solid" : "transparent" ) )
function layer_is_solid() {
try {
displayDialogs = DialogModes.NO
var solid = false
var doc = app.activeDocument
selection_from_layer()
invert_selection_from_layer()
try { doc.selection.feather(0) }
catch (e) { solid = true }
if( layer_is_empty( doc.activeLayer) ) solid = false
doc.selection.deselect()
displayDialogs = DialogModes.ERROR
return solid
} catch (e) {
displayDialogs = DialogModes.ERROR
throw ( 'layer_is_solid >> '+ e )
}
} // layer_is_solid
function selection_from_layer() {
try {
var r1 = new ActionReference()
r1.putProperty( chID("Chnl"), chID("fsel") )
var d = new ActionDescriptor()
d.putReference( chID("null"), r1 )
var r2 = new ActionReference()
r2.putEnumerated( chID("Chnl"), chID("Chnl"), chID("Trsp") )
d.putReference( chID("T "), r2 )
executeAction( chID("setd"), d, DialogModes.NO )
} catch (e) {
throw ( 'selection_from_layer >> '+ e )
}
} // selection_from_layer
function invert_selection_from_layer() {
try {
executeAction( chID( "Invs" ), undefined, DialogModes.NO )
} catch (e) {
throw ( 'invert_selection_from_layer >> '+ e )
}
} // invert_selection_from_layer
function layer_is_empty( artLayer ) {
try {
var bds = artLayer.bounds
if( bds[0].value || bds[1].value || bds[2].value || bds[3].value )
return false
return true
} catch (e) {
throw ( 'layer_is_empty >> '+ e )
}
} // layer_is_empty
function chID( a ) { return charIDToTypeID( a )}