3

I've got a Pages document "test" with a text box which has the text "Footnotes" in it. This text is marked as a placeholder text.

I want to change this text using AppleScript. This is what I've got so far:

tell application "Pages"
    activate
    tell document "test"
        tell current page
            set thistext to every text item whose object text contains "Footnotes"
            tell thistext
                tell its object text
                    set every word to mytext
                end tell
            end tell
        end tell
    end tell
end tell

Running this will result in the following error:

error "Can’t get object text of {text item 1 of page 1 of document id \"EB865803-005B-4C5D-A740-398B41B767F5\" of application \"Pages\"}." number -1728 from «class pDTx» of {«class shtx» 1 of «class cPag» 1 of document id "EB865803-005B-4C5D-A740-398B41B767F5"}

The script editor also marks the following lines:

tell its object text
     set every word to mytext
end tell

Any ideas? The goal is to fill the placeholder text on that page with a custom footnote.

2

set … to every … sets the variable to a list. That means thistext is a list, so you can't perform operations meant for the items in the to the list itself. You need a loop:

repeat with thistext in (every text item whose object text contains "Footnotes")
    …
end repeat

The full script is:

tell application "Pages"
    activate
    tell document "test"
        tell current page
            repeat with thistext in (every text item whose object text contains "Footnotes")
                tell thistext
                    tell its object text
                        set every word to mytext
                    end tell
                end tell
            end repeat
        end tell
    end tell
end tell
  • set thistext to the first text item whose object text contains "Footnotes"also worked – WalterBeiter Oct 24 '17 at 9:31
  • @Walter Yes that works if you only have one text item, I presumed you had many because you used ‘every’ :) – grg Oct 24 '17 at 9:34

You must log in to answer this question.

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