I’m trying to automate the creation of a Pages document with some text in the header and footer using Appplescript but I haven’t been able to figure out how to write there after creating the document from the “Blank” template.
I’m far from an AppleScript guru, but here’s the way I’d approach this.
First set-up a new template and create your own placeholders in the header (and footer).
I added a footer entry unimaginatively called “[My Footer]” as a placeholder too.
Then save that with a template name. I chose “Template01” for this example.
I was then able to use the AppleScript below to populate those placeholders along with some sample body text as follows.
-
[My Header]
→ My Heading Is This -
[My Footer]
→ My Footer Is Something Else - The body of the document is set to “Some example content for the body of the document”
tell application "Pages"
activate
make new document with properties {document template:template "Template01"}
tell front document
set tagMatch to {}
set strPHHeader to "[My Header]"
set strHeader to "My Heading Is This"
set tagMatch to the tag of every placeholder text whose tag is equal to strPHHeader
repeat with i from 1 to count of tagMatch
set tagCurrent to item i of tagMatch
set (every placeholder text whose tag is tagCurrent) to strHeader as text
end repeat
set strPHFooter to "[My Footer]"
set strFooter to "My Footer Is Something Else"
set tagMatch to the tag of every placeholder text whose tag is equal to strPHFooter
repeat with i from 1 to count of tagMatch
set tagCurrent to item i of tagMatch
set (every placeholder text whose tag is tagCurrent) to strFooter as text
end repeat
set body text to "Some example content for the body of the document"
end tell
end tell
Hope that helps.