Scripting Apple Pages

Hi

I am trying to put together a script which will create a series of tailored (ie lettered) pages in Pages which will then be used as cover pages for documents.

I have this:

set anumbers to {"A", "B", "C", "D", "E"}
set dname to "Mr Tester"
set datefield to "12 November 2010"


tell application "Pages"
	set frontdocument to open (path to current user folder as Unicode text) & "Library:Application Support:iWork:Pages:Templates:Default:NoMargins.template"
	--tell frontdocument
	repeat with pgn from 1 to 5
		tell body text of document 1
			set body text to "This is the page " & item pgn of anumbers & " from " & dname & " dated " & datefield
			insert page break
		end tell
	end repeat
	--end tell
end tell

It does not work, unfortunately. Ideally, I would like each page to have the text set out above on each page in ordinary size type along the top, with the letter (A,B,C,E,D etc) appearing, in addition, prominently in the middle of the page in very large type.

Can anyone point me in the right direction?

Thanks

Hi.

I think this solves the non-working bit:

set anumbers to {"A", "B", "C", "D", "E"}
set dname to "Mr Tester"
set datefield to "12 November 2010"


tell application "Pages"
	set frontdocument to open {file ((path to application support from user domain as Unicode text) & "iWork:Pages:Templates:Default:NoMargins.template")}
	
	repeat with pgn from 1 to 5
		tell front document
			set body text to body text & "This is the page " & item pgn of anumbers & " from " & dname & " dated " & datefield
			if (pgn < 5) then tell body text to insert page break
		end tell
	end repeat
	--end tell
end tell

Thanks, Nigel

Works great. Am working on the broader script with dialogs, autogenerating lists etc. I think I have that part in hand. Will post the final script when done.

But are you able to suggest how I might add a giant letter in the middle of each page? Can one manipulate fonts in Pages via applescript? I am not sure I have that bit in hand.

Cheers

Here is a starting point :


tell application "Pages" to tell document 1
	set body text to "K"
	tell body text
		set properties to {font name:"Zapfino", font size:300.0}
		get properties
	end tell
end tell

Here is a list of the available properties :
{
paragraph style:paragraph style “Format libre” of document id 5444167,
hidden:false,
shadow blur:missing value,
left indent:0.0,
subscript:false,
containing page:page 1 of document id 5444167, [ read only ]
keep with next paragraph:false,
italic:false,
label size:1.0,
shadow opacity:missing value,
bold:false,
character style:missing value,
color:{3598, 26728, 12850},
list style:list style “Aucun” of document id 5444167,
space before:0.0,
remove hyphenation:false,
label indent:0.0,
shadow color:missing value,
number label tiered:false,
underline type:none,
indent level:1,
tracking:0.0,
character background color:missing value,
font name:“Zapfino”,
label type:none,
first line indent:0.0,
number label style:number paren zero,
strikethrough type:none,
shadow offset:missing value,
start new page:false,
ligatures:default ligatures,
collapsed:false,
class:Unicode text,
font size:300.0,
space after:0.0,
line spacing:16.0,
capitalization type:normal capitalization,
label baseline shift:0.0,
text label string:missing value,
superscript:false,
right indent:0.0,
character offset:1,
scale with text:true,
line spacing type:at least,
contents:“K”,
outline:false,
shadow angle:missing value,
length:1,
label image data:missing value,
text indent:0.0,
shadow:false,
prevent widows and orphans:true,
alignment:left,
baseline shift:0.0,
strikethrough color:missing value,
underline color:missing value,
following paragraph style:missing value,
keep lines together:false,
paragraph background color:missing value
}

Yvan KOENIG (VALLAURIS, France) jeudi 18 mars 2010 19:44:29

Thanks

I had this up and running but the set font command seems to affect the whole document rather than the text added each time. Any suggestions as to how to limit the effect of set font to the added text only?

tell application "Pages"
	set frontdocument to open {file ((path to application support from user domain as Unicode text) & "iWork:Pages:Templates:Default:NoMargins.template")}
	repeat with pgn from 1 to totaldocss
		tell front document to set font name to "Arial Black"
		tell front document
			set font size to 14
			set body text to body text & "Document \"" & item pgn of anumbers & "\"  from " & dname & " dated " & datefield
			set font size to 72
			set body text to body text & return & return & "  \"" & item pgn of anumbers & "\""
			if (pgn < totaldocs) then tell body text to insert page break
		end tell
	end repeat
end tell
set anumbers to {"A", "B", "C", "D", "E"}
set totaldocs to (count anumbers)
set dname to "Mr Tester"
set datefield to "12 November 2010"

tell application "Pages"
	open {file ((path to application support from user domain as Unicode text) & "iWork:Pages:Templates:Default:NoMargins.template")}
	tell front document
		tell body text
			set font name to "Arial Black"
			set font size to 14
			repeat with pgn from 1 to totaldocs
				make new paragraph at end with data "Document \"" & item pgn of anumbers & "\"  from " & dname & " dated " & datefield & return & return with properties {font size:14, alignment:left}
				make new paragraph at end with data "\"" & item pgn of anumbers & "\"" with properties {font size:72, alignment:center}
				select insertion point after last paragraph
				if (pgn < totaldocs) then insert page break
			end repeat
		end tell
	end tell
end tell

Many thanks Nigel. Just what the doctor ordered. I can now complete the script and will post back.