Skip to main content
Participant
June 23, 2024
Question

color overlay to specific layer(s) jsx script

  • June 23, 2024
  • 3 replies
  • 486 views

hello! i'm new to jsx scripting, although i have fair experience with javascript. now my photoshop version is old and so i'm not using uxp. i want to loop through all layers and apply various blending options (are those called fx by any chance?) like color overlay, for instance. after a bit of googling, i found a solution that seems to be working:

applyColorOverlay(
{
    r: 255,
    g: 0,
    b: 0,
})

function applyColorOverlay(color)
{
    var desc6 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty(charIDToTypeID('Prpr'), charIDToTypeID('Lefx'));
    ref1.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
    desc6.putReference(charIDToTypeID('null'), ref1);
    var desc7 = new ActionDescriptor();
    var desc8 = new ActionDescriptor();
    desc8.putBoolean(charIDToTypeID('enab'), true);
    desc8.putBoolean(stringIDToTypeID('present'), true);
    desc8.putBoolean(stringIDToTypeID('showInDialog'), true);
    desc8.putEnumerated(charIDToTypeID('Md  '), charIDToTypeID('BlnM'), charIDToTypeID('Nrml'));
    var desc9 = new ActionDescriptor();
    desc9.putDouble(charIDToTypeID('Rd  '), color.r);
    desc9.putDouble(charIDToTypeID('Grn '), color.g);
    desc9.putDouble(charIDToTypeID('Bl  '), color.b);
    desc8.putObject(charIDToTypeID('Clr '), charIDToTypeID('RGBC'), desc9);
    desc8.putUnitDouble(charIDToTypeID('Opct'), charIDToTypeID('#Prc'), 100.000000);
    desc7.putObject(charIDToTypeID('SoFi'), charIDToTypeID('SoFi'), desc8);
    desc6.putObject(charIDToTypeID('T   '), charIDToTypeID('Lefx'), desc7);
    executeAction(charIDToTypeID('setd'), desc6, DialogModes.NO);
};


i got that from here:

https://graphicdesign.stackexchange.com/questions/120623/how-to-change-in-photoshop-script-color-of-smart-object-layer-or-rasterized-ima

now for one it's totally gibbrish for me, and for second, i want to add it to multiple layers based on my defined logic, so those leyers i want to put effects on won't be pre-selected, and this seems to be applying on a single and selected layer only. 

so i'm looking forward to a solution to achieve that. thanks!


This topic has been closed for replies.

3 replies

Stephen Marsh
Community Expert
Community Expert
June 24, 2024
quote

now for one it's totally gibbrish for me


By @Nishu382084082780

 

That the Action Manager code works is generally enough.  :]

 

The function can be rewritten/cleaned if that helps:

 

applyColorOverlay({r:255, g:0, b:0});

function applyColorOverlay(color) {
	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 descriptor3 = new ActionDescriptor();
	var descriptor4 = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putProperty(s2t('property'), s2t('layerEffects'));
	reference.putEnumerated(s2t('layer'), s2t('ordinal'), s2t('targetEnum'));
	descriptor.putReference(c2t('null'), reference);
	descriptor3.putBoolean(s2t('enabled'), true);
	descriptor3.putBoolean(s2t('present'), true);
	descriptor3.putBoolean(s2t('showInDialog'), true);
	descriptor3.putEnumerated(s2t('mode'), s2t('blendMode'), s2t('normal'));
	descriptor4.putDouble(s2t('red'), color.r);
	descriptor4.putDouble(c2t('Grn '), color.g);
	descriptor4.putDouble(s2t('blue'), color.b);
	descriptor3.putObject(s2t('color'), s2t('RGBColor'), descriptor4);
	descriptor3.putUnitDouble(s2t('opacity'), s2t('percentUnit'), 100.000000);
	descriptor2.putObject(s2t('solidFill'), s2t('solidFill'), descriptor3);
	descriptor.putObject(s2t('to'), s2t('layerEffects'), descriptor2);
	executeAction(s2t('set'), descriptor, DialogModes.NO);
}

 

c.pfaffenbichler
Community Expert
Community Expert
June 25, 2024

@Nishu382084082780 , can you provide some meaningful information or is the issue not that important after all? 

Stephen Marsh
Community Expert
Community Expert
June 24, 2024

@Nishu382084082780 


As @c.pfaffenbichler wrote, what is your "defined logic" to differentiate the layers that you wish to selectively process? Layer names? Layer kind? Layer position? Layer opacity or blend mode? Layer colour label? What?...

 

Please provide more details and a screenshot of the layers panel with any pertinent layers visible or groups/artboards and content expanded and visible.

c.pfaffenbichler
Community Expert
Community Expert
June 23, 2024

»multiple layers based on my defined logic« does not seem to clarify much, so please provide a meaningful description of the intended process. (How are the layers identifiable to which Layers Styles should be applied etc.?)