I have created a template in Pages (which consists of a text box placed at the bottom of the page and one line of text at the top).
What I would like to do:
Create a new document using the template; and
Place an insertion point after the one line of text so I can start typing further text.
As far as I have got with the script:
set ClientName to the text returned of (display dialog "What is the name: " default answer "first name and last name")
tell application "Pages"
activate
make new document with properties {document template:template "notary - legalisation instructions"}
end tell
From trying to understand what is available at https://iworkautomation.com/pages/index.html the line of text is classified as body text, but none of the pages appear to help in placing the insertion point.
At this point I have got stuck and would appreciate any help in what I need to do next.
Try to add the RETURN character to the last word of the first line of the text. I have not tried it, but logically it should give you what you need. How to refer to a certain paragraph of the text in the body, you will find in the dictionary of PAGES app. (first, second, last…)
Something such that:
display dialog "What is the name: " default answer "first name and last name"
set ClientName to text returned of result
set TemplateName to "notary - legalisation instructions"
tell application "Pages"
activate
make new document with properties {document template:template TemplateName}
tell the front document
tell the current page
set (paragraph 1 of body text) to (paragraph 1 of body text) & return & return
end tell
end tell
end tell
ONE NOTE: No need template at all. You can easy write top text and draw bottom text box with AppleScript.
Last time, the user remained silent. Apparently because I provided a not very visual example.
I think, they did not understand that there is no need to look for the text insertion point for this particular task. Because it is already known: after paragraph 1 of body text of current page.
Here is a more visual example, which I also tested.
-- script: INSERT typed text after 1st paragraph of Page document
-- written: by me right now
set typedText to text returned of (display dialog "Type text to insert after 1st paragraph of page" default answer "☠️ ")
set TemplateName to "Essay" -- one of existing templates of my Pages.app
tell application "Pages"
activate
make new document with properties {document template:template TemplateName}
tell the front document to tell (current page) to tell body text
set paragraph 1 to (paragraph 1) & return & typedText
end tell
delay 10 -- optional. Added only to see the result visually in the Script Debugger
end tell