title: Photoshop script to delete layer by name of multiple documents
body: <p>I'm trying to write a script that will go through multiple open documents and delete a layer by a certain name. When I run it, however, I get the following error: </p>
  
  <p>Error 8100: The requested action requires that the target document is the frontmost document.</p>
  
  <p>This is my code:</p>
  
  <pre><code>if( app.documents.length &gt; 0) {
      var LayerName = prompt("Which layer do you want to delete?","Layer name");
      RemoveLayers(LayerName); 
  }
  
  function RemoveLayers(LayerName){
      for(var i = 0; i &lt; app.documents.length; i++){  
          var actDoc = app.documents[i]; 
          var Layers = actDoc.artLayers;
          var len = Layers.length;
          for (var j = 0 ; j &lt; len ; j++) {
              if (Layers[i].name == LayerName) {
                  Layers[i].remove();
                  len--;
              }
          }    
      }
  }
  </code></pre>
  
  <p>Does anyone have any ideas as to why this is happening?</p>