Interact with Find & Replace window in Pages

I'm trying to automate a few steps with a .pages file using find/replace, and I'm having trouble interacting with the find/replace window. I used the click a button action to get the names of the buttons and click on them. This part works fine.

I have two problems:

  1. How do I tell KM to select the Find field and how do I tell KM to select the Replace field? Currently, I'm doing it by just tabbing.
  2. How do I close the window? I tried using the manipulate window action to close window by title: Find & Replace. But it doesn't work. I set a variable to %FrontWindowName%, but it just gives me the same name. Right now, I'm using cmd+W.

It's working as I have it, but I was just trying to make it more sturdy.

Ah, yes, very good. Also, as you have probably found, if you call up "Find" with -F (or the menu) and then activate "Replace", then "Replace" should be already available when you next call up "Find".

I don't think there will be a better way. Pages was evidently designed by a mouse-pusher who cared nothing for wider accessibility, so it's a miracle that we're allowed to do even that. I guess Apple had forgotten how to implement -F for find-and-replace like it had in TextEdit. Tabbing is alright though, isn't it? Moving between fields is a standard use of Tab, after all.

The standard Esc works, at least until the next version of Pages. :wink:

Esc is probably better. Thanks.

Here's a simple applescript that seems to work pretty good. It doesn't change values in a table, unfortunately. How do I include table values?

tell application "Pages" to tell the front document to tell the body text
	set (every character where it is "x") to "y"
end tell

Stick to using the Find dialog of you've got that working. While everything says that what you've done should work, we've found previously that scripting Pages like that gets more and more flakey as the amount of text increases -- and we're talking about a full single page of text, not 100s of pages.

Thanks for the advice. I'm scared of Applescript anyway.

Don't be scared of AppleScript -- you were most of the way there, but you were explicitly targeting only the body text (end of the first line).

Do be scared of Page's shonky implementation of AS, though!

1 Like