Copy link to clipboard
Copied
Hi,
I've just started down the road of coding with Javascript and would love some help.
I've been searching all over and I can't seem to find a simple way to change the color of layerSets.
//Create OLD Folder
var grpOld = app.activeDocument.layerSets.add();
grpOld.name = "OLD";
grpOld.visible = 0;
In my code I'll like to add a line that just assigns the layerSet to the colors available i.e. no color, red, orange, yellow, green, blue, violet & gray.
Any help on this would be great,
Thanks.
// 2023, use it at your own risk;
colorLayer ("violet");
////// change color //////
function colorLayer(theColor){
try {
var desc33 = new ActionDescriptor();
var ref10 = new ActionReference();
var idLyr = charIDToTypeID("Lyr ");
ref10.putEnumerated(idLyr, charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
desc33.putReference(charIDToTypeID("null"), ref10 );
var desc34 = new ActionDescriptor();
var idClr = charIDToTypeID("Clr ");
desc34.putEnumerated(idClr, idClr, stringIDToTypeID(theColor));
de
...
Copy link to clipboard
Copied
// 2023, use it at your own risk;
colorLayer ("violet");
////// change color //////
function colorLayer(theColor){
try {
var desc33 = new ActionDescriptor();
var ref10 = new ActionReference();
var idLyr = charIDToTypeID("Lyr ");
ref10.putEnumerated(idLyr, charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
desc33.putReference(charIDToTypeID("null"), ref10 );
var desc34 = new ActionDescriptor();
var idClr = charIDToTypeID("Clr ");
desc34.putEnumerated(idClr, idClr, stringIDToTypeID(theColor));
desc33.putObject(charIDToTypeID("T "), idLyr, desc34);
executeAction(charIDToTypeID("setd"), desc33, DialogModes.NO);
}catch(e){
alert(e.message);
}
};
Copy link to clipboard
Copied
Appriciate it.
Is this taken from the javascript listener? It just seems so bloated.
Is there no simplier way? I know I'm being picky it just seems an excessive amount of code for what seems like such a simple task.
Thanks.
Copy link to clipboard
Copied
That’s Action Manager code, so essentially what you would get with ScriptingListener.plugin (although it is slightly »cleaned up«).
Not all of Photoshop’s features are available via DOM code, so AM code it »has to be« sometimes.
The advantage being that AM code usually runs faster.
Copy link to clipboard
Copied
Ah okay I see. That's unfortunate but thanks for your help. Used your code and it works as intended so happy days.
I'm going to keep learning some more code and hopefully wrap my head around all this Javascript coding to move onto UXP.
Thanks again.
Copy link to clipboard
Copied
Best of luck with UXP!
I have tried familiarizing myself with that but so far I couldn’t muster the necessary focus and stamina.
But in the long run it will probably be unavoidable.
Copy link to clipboard
Copied
/*
No Color = "none"
Red = "red"
Orange = "orange"
Yellow = "yellowColor"
Green = "green"
Blue = "blue"
Violet = "violet"
Gray = "gray"
*/
Copy link to clipboard
Copied
Hi Stephen,
Thanks for that. How would I implement that in the code I put in at the top?
Thanks.
Copy link to clipboard
Copied
The function provided by @c.pfaffenbichler has a parameter for "violet" in the function call. Just swap that for one of the other named colours. The reason that I posted the list is that yellowColor isn't obvious.
Copy link to clipboard
Copied
Ah sorry. I get you. Thank you.