Creating new Pages documents is done using the make command from the Standard Suite. The optional with data parameter for the make command is currently not supported in Pages.
makev : Create a new object.
make
newclass : The class of the new object.
[ at locationspecifier ] : The location at which to insert the object.
[ with dataany ] : The initial contents of the object.
[ with propertiesrecord ] : The initial values for properties of the object.
⇒ specifier : The new object.
Using the make command, scripts can create Pages documents using the default template, as shown in the example script below:
New Default Pages Document
01
tellapplication "Pages"
02
activate
03
-- create a new document and store its reference in a variable
04
setthisDocumenttomakenewdocument
05
-- address the document reference
06
tellthisDocument
07
-- script actions go here
08
end tell
09
end tell
Here’s a script demonstrating how to use the optional with properties parameter to make a new document based upon a specific template:
New Document with Specified Document Properties
01
tellapplication "Pages"
02
activate
03
setthisDocumentto ¬
04
makenewdocumentwith properties ¬
05
{document template:template "Blank"}
06
end tell
In the current version of Pages there is a template, named “Blank,” for creating a blank word-processing document. There is no corresponding template for creating a blank page-layout document. A script can use the value of the document body property to determine whether a chosen template is designed for use as a page-layout document, and then delete all of its existing page items.
New Blank Page Layout Document
01
tellapplication "Pages"
02
activate
03
settemplateNamesto thenameof everytemplate
04
repeat
05
setthisTemplateNameto ¬
06
(choose from listtemplateNameswith prompt ¬
07
"Choose the template to use to create a blank layout document:")
display alert "WRONG TEMPLATE" message "The chosen template had an active document body." & return & return & "Choose a template that does not contain a document body text flow." buttons {"Cancel", "Try Again"} default button 2 cancel button "Cancel"
20
end if
21
end tell
22
end repeat
23
end tell
IMPORTANT TIP: Learn how to save and run your favorite scripts using the system-wide Script Menu.
Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. MACOSXAUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. MACOSXAUTOMATION.COM provides this only as a convenience to our users. MACOSXAUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and MACOSXAUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from MACOSXAUTOMATION.COM and that MACOSXAUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.