Search code examples
javascriptadobe-indesign

InDesign object model: number of current page


There is cursor on the page (one page - one text frame) in inDesign.

Is it possible with JavaScript to get number/id of current page (text frame) with cursor?

Probably solution app.activeWindow.activePage.name returns number of the page on the screen, but not number of page/text frame with cursor.

For example: if cursor set on page 3, but we see page 20 on the screen, app.activeWindow.activePage.name returns 20.


Solution

  • The activeWindow indeed is the page that is visible in your current view, and you can scroll away from the text cursor.

    To get the page that a cursor is in, first get the object that contains the cursor (usually a text frame) and then read its parentPage property:

    readonly The page on which this page item appears.

    Untested but it should be as easy as

    pagenr = app.selection[0].parentTextFrames[0].parentPage.name;
    

    where app.selection[0] is the current selection (for a 'clicked but not selected' text cursor its length is always 1), the parentTextFrames[0] refers to the frame containing the text and cursor, and then it's a short hop up to the parentPage and its properties.