Need help with a if then macro that matches on regex

Hi all

i have this macro

I’m trying to build a macro for Outlook with this behavior:

  • If a Mail window is already open (Inbox, Sent, Drafts, account view, etc.), just bring it to the front.

  • If only a Calendar window is open, then:

    • Create a new Mail window

    • Switch to Mail view

    • Resize it (Rectangle, etc.)

some things to considr:

  • I do not want to close or affect the Calendar window.

  • Mail window titles can vary (Inbox, Sent Items, Drafts, email address, etc.)

My issue is that using conditions like:

  • “Any window does not match…”

  • “No window matches…”

keeps triggering the “create new window” branch even when a Mail window exists.

What’s the most reliable way in Keyboard Maestro to detect the existence of at least one Mail-type window in Outlook, while ignoring Calendar windows?

thx so much!

Z

Isn't the Calendar window always called "Calendar"? Seems to be the case here, but I'm (deliberately) on Legacy Outlook.

If so, then this should work:

1 Like

wow @Nige_S thats amazing..

i spent like 1h with chatGPT/gemini but they both could not get to this elegant solution…i guess we are still safe…for a few more years at least heheh

thx again!

Z

Keyboard Maestro is not sufficiently main stream that LLMs like ChatGPT have any kind of deep understanding of it, so it tends to hallucinate the gaps.

By all mean feel free to ask ChatGPT how to do something, but expect it to just as likely be wrong as right, and when it is wrong, just ask on the forum where amazingly generous real people with real Keyboard Maestro experience are happy to help.

2 Likes

100% agree the people here on the forums are some of the nicest online :slight_smile:

and thx @peternlewis for making my life that much better each day in this crazy world we live in :slight_smile: :slight_smile:

2 Likes

Hi all!

revisiting this since i had to switch to the new outlook on mac because of work requerments (ughh i hate outlook:) …)

since then the macros stopped working. i can verify that the window title did not change


window frame: 7248,2063,400,65
Display Text: Calendar

Left: 7248
Top: 2063
Width: 400
Height: 65

Right: 7648
Bottom: 2128
MidX: 7448
MidY: 2095.5

name: Calendar
size: 1918,1063
pos: 5760,1096

Automatic

yet it just wont match anymore. for context this is the macro that worked flawlessly before

any clue what im missing here?

thx!

Z

The word Calendar appear multiple times in the image.

You might want to:

  1. Try \s*(Calendar) as the RegEx as this worked for the first occurrence.

  2. Provide the exact image to account for white space, etc.

Good luck and hope it works!

Doesn't work how? Does it always do the "execute" block, always do the "otherwise" block, throw an error about something?

It looks like you've already done one update, changing the "Select 'Mail'..." menu action to match the new menu item names. The "Activate" Action has picked up on "New" Outlook too, but if you haven't already then try setting the "If" Action to target "Any window title of: TextEdit" and then change it back to target "New" Outlook (you shouldn't need to do that, but it won't hurt to reset).

Not much comfort, but the macro works fine for me on both old and "New" Outlook -- if you do want the same macro to work for both Outlooks then change Go To to ^Go [Tt]o so it matches both lower- and upper-case versions, and the menu item Mail to ^(Em|M)ail.

thx @Nige_S

insane but the switch to "Any window title of: TextEdit" and then change it back to target "New" Outlook” did the job! ha! :slight_smile:

@Nige_S for the win again!! :slight_smile:

thx alot, truly appreciated!

Z