Length of Pages document with AppleScript

I have looked every where for the solution to this but cannot find one, I am trying to get the number of pages that a pages document contains. I obviously could check manually but what I am doing is automatically filling out a specific set of words so I need to ensure that the document remains less than one page. I have found two links (1, 2) that I thought would help but haven’t ended up working.

Does anyone have any other ideas on how I could check this?

TLDR: I am trying to use AppleScript to check the amount of pages in a document.

  1. Is the document already open in Pages, or are you attempting to check it from a Finder level?
  2. Can you share the exact script(s) you have tried , and the result(s), along with some details of your test document(s)?
    • The sources you listed look reasonable, but it may come down to how you have tailored and implemented them.

Thanks for the feedback, I was trying to get it from an already open Pages document but you gave me another idea of how to find it, which was to have my mouse curser go to the last page of the document and then check that page number. I then went thought the Pages documentation and was able to find a currentPage class exists. Finally, I reframed my search and found a IWorkAutomation. I found a page related to Sections that happens to parse the document based on sections to find the entire length.

So the command I ended up using is
set totalPages to the count of pages of every section

Thanks for making me think about it a different way!