How to make Pages go to a specific page

Pages lacks the ability to jump to a specific page, by giving it the page number.

How do I do that using AppleScript?

I see that Pages has no “go to page” command but I suspect you can manipulate other functions to do that, like the insertion point.

I have tried this command

	
	tell document 1
		select insertion point before (paragraph 1 where page number of page is 100)
	end tell

but it fails with the message

What you get is logical.
If you search for “number” in the Pages dictionary, you will find no occurrence.
From Applescript point of view, the page object has no “page number” property.

Yvan KOENIG running High Sierra 10.13.5 in French (VALLAURIS, France) mardi 26 juin 2018 15:00:06

There’s also no “select” and no “insertion point” in Pages’s dictionary and it doesn’t seem to recognise “before” either.

A second-best would be to use scripted keystrokes to scroll to the required page — although in some cases it would probably be faster to scroll manually using the scroll bars! This works with Pages 7.1 on my High Sierra machine, even though the keyboard doesn’t actually have the keys used. The delay times may need to be increased to improve the chances of hitting the right page.

tell application "Pages"
	activate
	set pageCount to (count pages of document 1)
	set targetPageNumber to (text returned of (display dialog "Go to page …" default answer "" with icon note)) as integer
end tell

tell application "System Events"
	set frontmost of application process "Pages" to true
	delay 0.2
	-- If the target page is nearer to the beginning of the document than to the end, go to the top and scroll down. Otherwise go to the bottom and scroll up.
	if (targetPageNumber < pageCount - targetPageNumber) then
		key code 115 -- or keystroke (character id 1) (Home key)
		delay 0.5
		repeat (targetPageNumber - 1) times
			key code 121 --  or keystroke (character id 12) (Page Down key)
			delay 0.2
		end repeat
	else
		key code 119 -- or keystroke (character id 4) (End key)
		delay 0.5
		repeat (pageCount - targetPageNumber) times
			key code 116 --  or keystroke (character id 11) (Page Up key)
			delay 0.2
		end repeat
	end if
end tell