Here is an AppleScript that replaces all placeholder text values in a Pages document that are listed in the keys_array with the dynamic list of Siri replacement strings that are in the values_array. The trick in a Shortcuts workflow is to pass a list of those replacement strings into a Run AppleScript input variable and use that as the values_array.
Code:
-- placeholder.applescript
(*
Replace every occurrence of key_array text strings in a Pages document with
their corresponding item from the values_array.
Reference: https://discussions.apple.com/thread/255475539?sortBy=oldest_first
Tested: macOS Sonoma 14.3, Pages v13.2
VikingOSX, 2024-02-14, Apple Support Communities, No warranties expressed or implied.
*)
use scripting additions
-- name of your placeholder text fields
set key_array to {"[Test_01]", "[Test_02]", "[Test_03]", "[Test_04]", "[Test_05]", ¬
"[Test_06]", "[Test_07]", "[Test_08]", "Test_09]", "[Test_10]", ¬
"Test_11]", "[Test_12]"}
-- the list of replacement items for this test
-- the real list will need to be passed from the Siri Shortcut action into a Run AppleScript action
set value_array to {"Var_01", "Var_02", "Var_03", "Var_04", "Var_05", ¬
"Var_06", "Var_07", "Var_08", "Var_09", "Var_10", ¬
"Var_11", "Var_12"}
if not ((count of key_array) = (count of value_array)) = true then return
tell application "Pages"
launch
if not (exists front document) then
display alert "Pages document must be open for this script to function properly."
if it is running then quit
return
end if
tell front document
repeat with i from 1 to count of key_array
set theTags to (the tag of every placeholder text whose tag contains (item i of key_array))
repeat with j from 1 to count of theTags
set thisTag to item j of theTags
set (every placeholder text whose tag is thisTag) to (item i of value_array) as text
end repeat
end repeat
end tell
end tell
return
Results on a Pages document with 12 Placeholder text fields:
