How to update specific layer comps via action manager jsx

Here’s a challenge… I am trying to find a way to update say, the visible states of several layers on a subset of layer comps. As far as I can tell, the action manager reference to which comps to affect only accepts the selected comps in the panel. I can’t give it an id, index, or list like I would for layers.

In fact… simply trying to use getReference() on a layer comp ref throws an error!


var ref = new ActionReference();
ref.putEnumerated(stringIDToTypeID('compsClass'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
// ref.putIdentifier(s2id('compsClass'), compId);// only works if getting properties
// ref.putIndex(stringIDToTypeID('compsClass'), 0);// only works if getting properties

var refDesc = executeActionGet(ref);// this crashes

var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID('null'), ref);  
var result = executeAction(charIDToTypeID( "getd" ), desc, DialogModes.NO);//this also crashes

Error Code# -25920: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
– The command “Get” is not currently available. @ file ‘’ [line:0, col:NaN]

I can do what I want to so long as I have the correct layer comps already selected with this:

c2id = charIDToTypeID,
s2id = stringIDToTypeID;

var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated(s2id('compsClass'), c2id('Ordn'), c2id('Trgt'));
    // ref.putIndex(s2id('compsClass'), 0);
    // ref.putIdentifier(s2id('compsClass'), compId);
    desc.putReference( c2id('null'), ref );
desc.putBoolean( s2id('useVisibility'), true );
desc.putBoolean( s2id('useAppearance'), false );
desc.putBoolean( s2id('usePosition'), false );
if(Number(app.version.split('.').shift()) >= 22) {
    desc.putBoolean( s2id('useChildLayerCompState'), false );
}
desc.putBoolean( s2id('selected'), true );

executeAction( s2id('recapture'), desc, DialogModes.NO );

but if I try with an index or id as the reference, it does nothing.

The regular javascript API won’t even let me get that far… just apply or refresh the entire comp.

So do I have to go through each comp and apply, then manually toggle the visibility states for the affected layers, then refresh the comp? Cause that seems like it would be… less than performant.

My experiences so far with automating layer comps has been incredibly frustrating. You can only get the ‘selected’ state via the regular API, but you can only get the ID via action manager, and you can only get the ‘applied’ state by asking for the JSON property of the document and parsing the comps object from that…