1

I have created a Pages document with a template, and I want to add a page to the document using one of the pages in the document's template.

Something like:

tell thisDocument to make new page with properties { template:"Image with Text" }

I've searched the iWork Library and don't see where it is possible.

This is the AppleScript equivalent of "Add Page" that has a drop down of pages in the template:

enter image description here

2
  • 1
    A side note: maybe instead of make new page with properties { template:"Page template" } there is something like make new page and then apply property {template:"Page template"}
    – jsx97
    Jul 10, 2023 at 20:02
  • 1
    @jsx97 We're in 2023 now xD
    – Thinkr
    Jul 11, 2023 at 9:05

1 Answer 1

2
+150

You can use a simple AppleScript which creates a new Pages document with the specified template, adds a new page to the document and then saves the document as a template with the specified name. Here it is:

tell application "Pages"
    activate
    set thisDocument to make new document with properties {document template:template "Template Name"}
    tell thisDocument
        make new page with properties {template name:"Image with Text"}
    end tell
    set templatePath to (path to desktop as text) & "Template Name.pages"
    save thisDocument in file templatePath as "template"
end tell

Make sure to replace the two "Template Name" 's with the wanted name of the template, replace "Image with Text" with the name of the page template you want to add to your document, and replace "path to desktop as text" to the location where you want to save the template in your desktop.

Note: Saving a document as a template will overwrite any existing template with the same name, so if you want to replace the previous template, you might want to use the same name.

11
  • Sorry for late reply, I was solving problems of one of my friends. Are you sure everything is correct here? It seems to me there is an error right in the second line: set thisDocument to make new document with properties {template:"Template Name"} (I have changed Template Name to Blank). "Script error: Pages got an error: Can’t make {template:"Blank"} into type properties of document."
    – jsx97
    Jul 16, 2023 at 10:51
  • I have also tried to change your script as shown here, but there is still the same error.
    – jsx97
    Jul 16, 2023 at 13:02
  • @jsx97 This is because there is no template named "Blank" in Pages. The correct template name would be "Blank Template" in this case. ;)
    – Thinkr
    Jul 17, 2023 at 8:53
  • Well, I will award the bounty because it expires today, but unfortunately the solution still doesn't work, even after I have changed Blank to Blank Template in both instances of the script. Solving this issue with AppleScript is quite important for me, so I will be very apprericated for futher assistance
    – jsx97
    Jul 17, 2023 at 11:57
  • 1
    @jsx97 Hey, sorry for the delay but I'm not letting you down. I've managed to get make new page with properties {page template "image"}, which has the correct formula (I think). I've just tried with creating a custom page template (image). With this, I still get an error: Pages got an error: Can’t get template "image" of document id "9D17A04A-D11A-43CE-BBE4-363B24294935".. I think I need to find the page template path and add it there, currently trying to do this. :)
    – Thinkr
    Aug 22, 2023 at 9:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .