6 Replies Latest reply on May 6, 2016 9:04 AM by JustOneBren

    Select All Script

    JustOneBren Level 1

      Hi All,


      Hoping someone out there can help, I need my script to end it with one of the following 3 options:

      Select All: as in 'cmd a'

      Select all objects on "Tabs" Layer

      Select all objects with Script Label "Tab Boxes"


      Reason being, when the script ends I need a bunch of boxes to be pre-selected ready for a manual deselect of 1 item (chosen by the user) and then they will delete the pre-selected objects manually to finish off. (I haven't included my original script here as will have no bearing on the standalone part I need for the final selection)

      Hoping this is a simple script but as it's unusual to have a script selecting objects and not doing anything with them, I'm finding it impossible to create.


      Many Thanks, Bren

        • 1. Re: Select All Script
          Peter Kahrel Adobe Community Professional & MVP

          Read the object model and you'll find that the script equivalent of Cmnd+A is this:


          app.selection = null;
          pItems = app.windows[0].activeSpread.pageItems;
          app.select (pItems, SelectionOptions.ADD_TO);


          To select all page items on the Tab layer, filter the page items:


          app.selection = null;
          pItems = app.windows[0].activeSpread.pageItems;
          for (i = pItems.length-1; i >= 0; i--) {
            if (pItems[i].itemLayer.name === 'Tab') {
              app.select (pItems[i], SelectionOptions.ADD_TO);


          To select objects with a certain script label is a variant of (or an addition to) the second script.



          • 2. Re: Select All Script
            JustOneBren Level 1

            Many Thanks for that Peter, the second script has worked perfectly.

            The reason I haven't been able to use the first script is that it selects everything on locked layers too and then I would have to add more scripts to hide and unhide all other layers to deselect the other objects. I'm quite new to scripting (started about a week ago) and don't have a great knowledge of the Object Model, working on it but not there yet.


            Thanks again, Brendan

            • 3. Re: Select All Script
              Peter Kahrel Adobe Community Professional & MVP

              To exclude locked items or those on locked layers, use a filter. In other words, a variant of the second script. Replace this line:


              if (pItems[i].itemLayer.name === 'Tab') {


              with this:


              if (pItems[i].locked === false) {



              • 4. Re: Select All Script
                JustOneBren Level 1

                Tried replacing the script line but it then selects unlocked items on hidden and locked layers as it's looking at the document as a whole and not just the "Tabs" layer.

                Pity it doesn't just work the same as Cmd+a, as in, it can work on the whole document but it only selects objects that are not on hidden or locked layers but I think this is a very niche requirement.


                Many Thanks again,



                • 5. Re: Select All Script
                  Laubender Adobe Community Professional & MVP

                  Hi Brendan,

                  no problem. For cmd+a you could use the keyboard command:


                  app.menuActions.item("$ID/Select &All").invoke();


                  The try/catch is probably necessary, if this command is grayed out under any circumstances and is not available in the UI.



                  • 6. Re: Select All Script
                    JustOneBren Level 1

                    That works perfect too Laubender, that will definitely be of use as well.


                    Pity I can't highlight 2 replies for correct answer!


                    Many Thanks for that, Brendan