Feature request: Exception for Press Button

I’m not proposing adding exceptions generally.
That would be one huge nightmare.

But many macros depend upon clicking a button in a dialog box in an application.
When that fails, KM knows, and depending on the check box, will stop the macro or continue it.
The frustrating thing for me is that KM knows, but I don’t.

I work a lot in Pages documents, for instance, and choose menu items.
One thing I do is put two values in the Search and Replace dialog.
Then I want to press the button ‘Replace All’.
But if the search term is not in the document, the Replace All button is greyed out, and the macro fails without a word, or continues on to do … well, I can’t be sure.

So on the Press Button I would like three options:

If the button cannot be pressed:
Stop macro (as now)
Continue (as now)
Set Variable … to … (proposal)

I could then set vSearchFailed to yes, then use if…then to recover, or to finish gracefully.
Jim

Sure you do - do the Press Button action, turn off the Cancel Macro option, and check the %ActionResult% token in the immediate next action. It will be OK for success, something else for any error.

Hey Jim,

It’s beyond belief that Pages 5 can’t do a scripted search…

KM may be doing what you need, but you can get still more sophisticated with System Events and UI-Scripting.

Create a new document with one or more instances of the text search, and then run the script from the Applescript Editor.

tell application "System Events"
  tell application process "Pages"
    set frontmost to true
    click menu item "Find…" of menu 1 of menu item "Find" of menu 1 of menu bar item "Edit" of menu bar 1
    if name of front window = "Find & Replace" then
      tell window "Find & Replace"
        set value of text field 1 to "Search"
        set value of text field 2 to "me"
        delay 0.7 # You may have to fiddle with this to get the timing right.
        if button "Replace All" exists then
          tell button "Replace All"
            if it is enabled then
              click
            else
              false
            end if
          end tell
        end if
      end tell
    end if
  end tell
end tell

Although it looks ugly it’s a simple example. Much more powerful things are possible.

-Chris

Peter
Many thanks for this.
It was just what I wanted.

Can I suggest that somewhere near %ActionResult% in the manual you add the words “exception processing” so people a little familiar with programming, but not very familiar with this excellent macro language, might find it?

Thanks
Jim

Chris
Thanks for that.
Yes. I was shocked too, on switching from Win/Word to Mac/Pages to find no simple scripting.

It may seem unlikely, but I am looking for less powerful scripting.
As I am a member of an online group that all have a terminal condition, succession is always on my mind.
I am rewriting my macros so they act more like primitive Word macros so my successor has a better chance of being able to understand what is going on, and make necessary mods.

Using straightforward KM macros to do tasks in Pages or Numbers using menu commands seems to be the best way forward.

Thanks for your help.
Jim