How can I apply this code only to the 2nd layer of every PSD file? I also want to avoid color selection instead give the hex color code of black to remove.

var doc = app.activeDocument;
for(var i = 0; i < doc.layers.length; i++){
    doc.activeLayer = doc.layers[i];
    doc.activeLayer.visible = false;

The code appears here: How do I delete all white pixels from several layers?

  • That script is a loop for running an action on multiple layers in the same document, not single layers within multiple documents. – Billy Kerr Aug 2 '17 at 7:35
  • This is probably more suitable for apple.SE or SuperUser.SE – Luciano Aug 2 '17 at 9:44
  • @Luciano but it's also on-topic here, or we wouldn't have the photoshop-scripting tag. – Vincent Aug 10 '17 at 9:19
  1. Press Alt + F9 to open Action window
  2. Click on "Create a set" button and rename it to mySet enter image description here
  3. Click on "Create an Action" button and rename it to myAction
  4. Go to Select -> Color Range (selected black) pressed OK then hit Delete
  5. button on keyboard to delete the black colors, and then press CTRL + D to deselect the current selection
  6. Press Stop button in Action window
  7. open notepad and copy and paste the following code
    var doc = app.activeDocument;
    doc.activeLayer = doc.layers[1];
    app.doAction("myAction", "mySet");

In notepad save the file with ".jsx" extention

go to Photoshop -> File -> Scripts -> Browse... and select your script and run it. This script will run Action on your second layer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.