I’ve been away from AppleScripting for a while and haven’t tried to script Pages before so I am not sure why I am getting this error:
tell application "Pages"
make new document with properties {template name:"DeveloperGuide"}
tell front document
set bodyText to body text
return bodyText
end tell
end tell
in the log: missing value
There is a text box in the document but maybe I am not understanding what body text is suppose to return. The dictionary says: body text (text) : The main text flow of the document.
I am just looking to do some simple add pages to an existing template and some text to it. Thanks for any help.
Can’t really tell much without having your template. Basically, ‘body text’ is, as you’ve seen, the main text flow of the document. If there’s none, you’ll get ‘missing value’ instead of text as its value. If the document contains text boxes, any text they contain is their ‘object text’:
tell application "Pages"
make new document with properties {template name:"Informal Newsletter"}
tell front document
set objectTexts to object text of text boxes
return objectTexts
--> List containing the object text of each text box.
end tell
end tell
You aren’t working in Word Processing mode but in Layout one.
As I am a French user, I’m not accustomed to English templates names.
I’m not sure that “DeveloperGuide” is an Apple one.
In Layout mode, there is no main text layer (body text).
Every text data must be in text boxes.
In Word Processing mode, there is a main text layer flowing along the entire document from page 1 to late one.
Of course, you may also insert text datas in text boxes but it’s an other story.
Here are tests allowing a script to know if a document is a WP or a Layout one is what you coded
tell application "Pages"
set isLayout to body text of document 1 is missing value
set isWP to body text of document 1 is not missing value
(*
# this instruction is OK for WP but it fails with Layout
set isWP to class of body text of document 1 is string
*)
# so it would be required to enclose it in a try block
try
set isWP to class of body text of document 1 is string
on error
set isWP to false
end try
try
set isLayout to class of body text of document 1 is not string
on error
set isLayout to true
end try
end tell
KOENIG Yvan (VALLAURIS, France) mercredi 11 septembre 2013 18:13:00
OK, that was painful to look up and write. Back to Anglais. I get what you were saying about the word file/layout file difference and you are correct, the template is a layout file but it also has a text box placed on it, wouldn’t that appear in the text flow?