Pages: How to use the page number in applescript

Can someone tell me how to use the page number property of Pages in Applescript?

I have tried things like.

set PageNumber to page number of page of document "xxx.pages"

.and it is not working.

Is there any guru out there that can please tell me how to use it? and what about page footer and page header?

Thanks.

The problem with in that script is that you’re not telling Pages which page you want the page number for. (Yes, you would have to supply a number.)

This is all I can come up with.

tell application "Pages"
	count pages of front document
end tell

tell application "Pages"
	-- Does this document have a second page?
	exists page 2 of front document
end tell

ok, but in your example you are not using the PAGE NUMBER command.

PAGE NUMBER is present on the dictionary and in theory can be used (I suppose) to discover the actual page number.

let me give you an example of what I am trying to do…


tell application "pages"
select paragraph 122 of body text of document "xxx.pages"
-- this will select the paragraph 122 of document xxx.pages

-- now how can I discover the page where this paragraph is????
set WhereIsIt to page number of document "xxx.pages"  ???
 
end tell

This is a mistery!!!:rolleyes:

It’s not a command. Page number is a property of the page class “ a class which, according to the dictionary, only supports the count, exists, and get commands “ that is contained by either a document or a section. Thus, the page class, and its properties, are of very limited use (for now, at least).

I know what you’re trying to do; you’ve mentioned it before (Pages: Get page number of paragraph). I’ll answer again:

What you want to do is not (currently) possible.

So, ok. I am just trying to figure out how it works.
what’s the point of having a property you cannot read or figure out how to use t?
PAGE NUMBER is an useless property.

You say PAGE NUMBER only supports exists, count and get.

I tried exists…


exists page number of page 1 of document "xxx.pages"
display dialog return

Pages answer to these lines: Pages got an error: NSInternalScriptError

Then I tried count


display dialog count of page number of page 1 of document "xxx.pages"

and got: Pages got an error: NSOperationNotSupportedForKeyScriptError

changing the previos script to


display dialog count of page number of document "xxx.pages"

gives me ZERO as answer all times, any document, any number of pages, always zero.

in fact I suspect that page number property cannot be read, never and is not working.
If you know how to use it, I mean, how to READ the property PAGE NUMBER please tell me before all hair in my head falls…
thanks and sorry bothering you too much… you must be tired of me. :rolleyes:

No, I was talking about the Page class.

Edit: You should send feedback: Feedback - Pages - Apple

ok. no problem.
I figured out that you don’t know the answer to my question.
anyway, thanks.

But he did answer your question macos_boy, he said that in the current state of development of Pages, the operation you are asking for is NOT POSSIBLE. Seems straight-forward to me. Which part didn’t you get?

I will not raise a point on this, but it would be simpler if the answer was one of the two following alternatives:

  1. PAGE NUMBER property cannot be read in Pages, due to a bug or
  2. I don’t know how to use it.

Both answers were perfect, but none was given.

Of course, the second answer would not be apropriate in a forum like this.

If one say that something cannot be done you never know if the one is talking about a bug or about a true impossibility (due to a lack of commands).

Anyway, I thank you for your answers.

But it actually isn’t really a bug - the Dictionary of Pages is not all implemented and doesn’t promise a means to extract a property called “Page Number”.

Anyway, you never did tell us why you wanted it. I can imagine two reasons (but your mileage may vary):

  1. You want a fast way to get back to something
  2. Actually knowing what page something is on has importance to your project.

If 1, you can use “offset” for example to at least locate a unique character(s) in the total text string or use text item delimiters set to something large and unique on a page to find it again.

If 2, your scheme is in trouble. Pagination is a complex matter of formatting, insertions, and layout. AppleScript doesn’t know anything about those so unless the application will tell you, there’s no way for a script to discover them.

And a last point. Nobody ever feels safe saying “never” in a forum, so when they can’t think of any way and the dictionary of the application doesn’t point one out, they say something cannot be done, but they don’t really know why.