You may try the following script. You need to enable System Preferences > Universal Access > Enabel access for assistive devices.
Regards,
H
(*
find & replace > advanced (Pages 09)
*)
Pages_replace_all_advanced("banana", "pumpkin", {|whole word|:1, |match case|:0})
on Pages_replace_all_advanced(x, y, options)
(*
string x : search string
string y : replace string
record options : search & replace options
|search area| : 1 = entire document, 2 = main text body (default = 1)
|match case| : 0 = disabled, 1 = enabled (default = 0)
|whole word| : 0 = disabled, 1 = enabled (default = 0)
|search loop| : 0 = disabled, 1 = enabled (default = 1)
*)
set options to options & {|search area|:1, |match case|:0, |whole word|:0, |search loop|:1}
tell application "Pages"
if not (exists document 1) then return
activate
end tell
tell application "System Events"
tell process "Pages"
set find_panel_new to not (exists (window 1 whose subrole = "AXDialog"))
if find_panel_new then
keystroke "f" using command down
repeat until exists (window 1 whose subrole = "AXDialog")
delay 0.2
end repeat
end if
tell (window 1 whose subrole = "AXDialog") -- find & replace window
tell tab group 1
tell radio button 2 -- 1 = simple, 2 = advanced
click
end tell
tell checkbox 1 -- search previous text (loop)
if value ≠ options's |search loop| then click
end tell
tell checkbox 2 -- match case
if value ≠ options's |match case| then click
end tell
tell checkbox 3 -- whole word
if value ≠ options's |whole word| then click
end tell
tell pop up button 1 -- search area (entire document | main text body)
click
tell menu 1's menu item (options's |search area|) to click
end tell
tell scroll area 1's text area 1 -- find
set value to x
end tell
tell scroll area 2's text area 1 -- replace
set value to y
end tell
tell button 3 -- replace all
click
end tell
end tell
if find_panel_new then click (button 1 whose subrole = "AXCloseButton")
end tell
end tell
end tell
end Pages_replace_all_advanced