I have a macro that pops up a contextual menu, selects the item that starts with “30” but does not click it. I’ve tried two ways of accomplishing this. First is using Found Image to click the contextual menu’s button:
This works very fast (when it works), selecting the “30” line pretty much instantly. The problem is that the Found Image step is not very reliable, no matter how I fiddle with the “fuzziness” adjustment or search image.
The second method is to use an AppleScript to click the contextual menu’s button as follows:
With this method, the contextual menu pops up completely reliably and instantly. BUT, then the selection of the “30” line takes about 2 seconds to occur.
I’m looking for a way to use the AppleScript, but to get the line selection in the contextual menu to happen as fast as it does with method #1. Any help would be appreciated.
I don't use Outlook at all, but maybe try the Press a Button When Enabled action, and have it read in Outlook's active buttons (using the gear icon on the right side of the action). Then look through the buttons and see if can find something that matches what Button 2 might be.
(You can use the Action's "Button" pop-up to first scan the front window of Outlook and, after that, select the button you want to press.)
I don't have the "30" option so can't test, but if you are on Sequoia or later you should be able to spring the Contextual menu and type your way through it. Something like:
You may have to add "Pause: 0.2s" or similar between Actions sp the macro doesn't run ahead of the UI -- try it and see.
Since it is on Outlook's toolbar you could improve the reliability of your original "Click at Found Image" Action by selecting "area" instead of fullscreen -- even limiting the search area to the top 200px of the frontmost Outlook window will greatly reduce the errors you are getting from scanning your entire screen. But I'd save this for if you can't get the button or menu item methods to work.
Your AppleScript is probably slow because the click action waits for Outlook to respond with an "OK, done that" before continuing -- and Outlook takes a while to reply to System Events calls. You might be able to speed things up by ignoring application responses
tell application "System Events"
tell process "Microsoft Outlook"
ignoring application responses
click button 2 of front window
end ignoring
end tell
end tell
...but you'll then have to add a "Pause" action after the AppleScript to give the menu time to arrive before you start typing. You might then be swapping speed for reliability...
Your AppleScript is probably slow because the click action waits for Outlook to respond with an "OK, done that" before continuing -- and Outlook takes a while to reply to System Events calls. You might be able to speed things up by ignoring application responses
...but you'll then have to add a "Pause" action after the AppleScript to give the menu time to arrive before you start typing. You might then be swapping speed for reliability...
@Nige_S Thank you! You got me on the right track. ignoring application responses didn’t help, but that led me to try KM’s option to run the script Asynchronously. This allowed KM to continue right away to the next macro step without waiting for Outlook. As you point out, it requires a short pause after the AppleScript to allow time for the menu to pop up. It seems that 0.3 seconds is the sweet spot for reliability while getting ride of the perceptible delay.
BTW, KM’s Press Button (“Snooze Options”) does work just like the AppleScript, but there’s no asynchronous option, and so the delay is still there using that action.