Applescript, Pages 5.2 and text placeholders example

Hi

I'm looking for a very basic example of using Applescript and text Placeholders in Pages 5.2


I have a pages doc with a placeholder - "text1" - same placeholder - 2 occurrences.

This is saved as a template


The following script creates the doc but does not find the text .

tell application "Pages"

activate

-- Get new text

repeat

display dialog "Enter the new text:" default answer "NewText"

set replacementNewText to the text returned of the result

if replacementNewText is not "" then exit repeat

end repeat


-- Make new doc from template

set thisDocument to ¬

make new document with properties {document template:template "testdoc"}


tell thisDocument

-- Replace text

set placeholderText to "text1"

set theseTextItems to ¬

every text item whose object text contains placeholderText

repeat with i from 1 to the count of theseTextItems

set thisTextItem to item i of theseTextItems

tell thisTextItem

tell its object text

set (every paragraph where it is placeholderText) to ¬

replacementNewText

end tell

end tell

end repeat

end tell

end tell



When I run the script - I can see that it does not find the text ... what am I missing?


If I look at the what's happening - I see the following:

tell application "Pages"

activate

display dialog "Enter the new text:" default answer "NewText"

--> {button returned:"OK", text returned:"NewText"}

make new document with properties {document template:template "testdoc"}

--> document "Untitled 1"

get every text item of document "Untitled 1" whose object text contains "text1"

--> {}



Appreciate any pointers provided :-)


Thanks

Applescript, Pages 5.2 and text placeholders example
 
 
Q