4 Replies Latest reply on May 22, 2012 7:18 AM by mvtimes

    Get current page or page of selected item



      I' d like get the current page in Indesign or (if this is not possible) the page of a selected object.

      How could I implement this?


      var page = app.selection[0].page;

      does not work.


      Thanks and kind regards,


        • 1. Re: Get current page or page of selected item
          Marijan Tompa [tomaxxi] Level 4

          What's your InDesign version?








          • 2. Re: Get current page or page of selected item
            [Jongware] Most Valuable Participant

            The current page:


            var page = app.activeWindow.activePage;

            alert (page.name);


            -- this is the page that is active & visible on your screen (not the one selected in the Pages panel! -- I think I told someone else that a while ago).

            If there are parts of more than one page visible, ID seems to select one by some fixed rule ('biggest part visible', 'first one when seen left to right', 'the top one if it shows more than half of it' -- something like that).



            (Post-Edit) Oh and this property has nothing to do with the current selection. I guess it depends on what you want to do next.

            • 3. Re: Get current page or page of selected item
              PankChat Level 1

              Another way getting that done is based upon what is your current




                              var myPg=getPage(app.selection[0]);

                              alert (myPg.name);




              function getPage(theObj)


              if (theObj.constructor.name == "Page") return theObj;

              if (theObj.constructor.name == "Character" || theObj.constructor.name ==


              return getPage(theObj.parentTextFrames[0]);

              if (theObj.constructor.name == "Application")


              // Frame is on an unexpected place...

              alert ("Can't able to find the page");



              return getPage(theObj.parent);


              • 4. Re: Get current page or page of selected item
                mvtimes Level 1

                Once more, thank you for your help.


                After trying again and again, I added an alert to try to track the changes, and things started to work. This led me to the conclusion that the content wasn't actually on the page yet. Looking again, I had my importXML command within the main function, so the rules weren't being applied because content hadn't actually been placed on the page yet. I still find it odd that all my other rules were working, but it seems that if the content is already on the page, then this rule works too. Odd, but seemingly what's happening.