2 Replies Latest reply on Jun 19, 2013 8:40 AM by ggreenbe

    Converting Simple Indesign AppleScript to Javascript




      I have been using as imple Indesign AppleScript but need to convert it to javascript and have no prior experience.  I've been reading the Adobe pdf about scripting and it is great as it shows the differences between the 3 (as, js, vb) but I'm still having trouble figuring out how this would conver.  Would anyone be able to show me the converted result?



      tell application "Adobe InDesign CS5.5"

           tell every document
                set visible of layer "Interactive - Web" to true
                set visible of layer "Interactive - Print" to false
           end tell
      end tell



      var myDocuments = app.documents.everyItem(); // something like this?


      It hides/shows the visibility of 2 specific layers for all opened documents.  I pretty much need to hide/show 2 specific layers ina  book and this should/can accomplish that.


      Thanks for any help!

        • 1. Re: Converting Simple Indesign AppleScript to Javascript
          dln385 Level 2

          This should work:


          var documentsArray = app.documents.everyItem().getElements();
          for (var i = 0; i < documentsArray.length; i++) {
                    var document = documentsArray[i];
                    var layers = document.layers;
                    layers.itemByName("Interactive - Web").visible = true;
                    layers.itemByName("Interactive - Print").visible = false;



          Also, it might be possible to do this without using "getElements" which "resolves the object specifier", eliminating the need for the "for" loop. Something like this:


          app.documents.everyItem().layers.itemByName("Interactive - Web").visible = true;
          app.documents.everyItem().layers.itemByName("Interactive - Print").visible = false;
          • 2. Re: Converting Simple Indesign AppleScript to Javascript
            ggreenbe Level 1

            Thanks, worked perfectly!