Thank you very much! It works so well now. Can I ask you one more question? Where can I learn to code like this? Could you please recommend any websites or courses for beginners to learn JavaScript?
By @GiangHg999
If you are relatively new to Photoshop Scripting you may want to avoid ESTK Scripting, as it is unclear how long it will be supported, and focus on UXP Scripting right away.
@DBarranca has published a book on the issue; I haven’t purchased it yet, but I suspect it may make for easier reading than the documentation Adobe itself offers.
https://www.ps-scripting.com/professional-ps-uxp.html
Thanks for the mention, @c.pfaffenbichler
The UXP code (write it in a `.psjs` file and call it via File > Scripts > Browse...) would be:
const { app, constants } = require("photoshop");
const processLayer = (layer) => {
if (layer.kind === constants.LayerKind.GROUP && layer.layers) {
for (let l of layer.layers) {
processLayer(l);
}
} else if (layer.kind === constants.LayerKind.SMARTOBJECT) {
layer.selected = true;
}
};
const startLayer = app.activeDocument?.activeLayers[0];
if (startLayer) {
startLayer.selected = false;
processLayer(startLayer);
}
Hope this helps!