How Can I Use Standard Gmail Shortcuts in Apple Mail with Keyboard Maestro?

I've been trying to create a series of macros to be able to use Gmail shortcuts with Apple mail using the help of Keyboard Maestro. After I've completed about 75% of the shortcuts, it occurred to me that when typing the text of an email certain letters will conflict with the macro triggers.

For example, I have set the letters J and K as triggers to move to the next or previous message. This, of course, conflicts when you are just typing an email that has words that contain the letters K or J in them. Does anybody know of a solution where regular typing doesn't conflict with the macro triggers (I.e. navigation)?

Is there a way to make the triggers not active with a specific window is in front (i.e. the compose window)?

52%20AM

You could make a condition of the macro executing being that the menu item "Send" is inactive.

That way if you are composing a message (and the Send item is active), it won't trigger.

Is it the "If then, else" action?

What Trigger would you use to accomplish this? I don't see any triggers that allow a condition of menu status.

Try changing the macro group's settings to this:

Regex used: ([^)]+)$

Assuming the title of every mailbox view in the main Mail window ends with something in parenthesis, this should prevent the macros from being triggered when in any other window, like the message composer.

Like so:

08%20PM

That's very clever, @gglick, and may be as close as you can get.
The only pitfall I see is if the Subject in the Compose window ends with a ")", like this:
Test with (Parenthesis)

But that may be close enough for @bocciaman. :wink:

1 Like

Well, I was imagining something like this:

I haven't tested it very thoroughly, so I can' t say if there are any problems with it.

Obviously it would need to be in a Macro Group which is enabled only for Mail.app.

Hey, hey now, @JMichaelTX! If a Macro doesn't work quite right I don't use it, I go back to the drawing board and start over. :sweat_smile:

1 Like

That may work too, but the exact setting I verified worked for me was this:

Yes, it's definitely not foolproof, but given how infrequent ending parenthetical statements are in email subjects and how common they are in the main Mail window, I figured it would indeed be as close as you can get.

@peternlewis has stated numerous times that a macro that types the same keystroke that is used to trigger it can lead to unpredictable behavior. For example, it might just re-trigger the macro. Or, it might not. Unpredictable.

Also, how do you know whether to type a lower or upper case "J"?

@JMichaelTX You are right, it is unpredictable. I've completed all the macros and added the regex to the group that was suggested by @gglick. But all of a sudden, when I type "s" even in the compose window it triggers the Flag (⇧⌘L) star/flag macro due to what I setup. Therefore, I'm giving up on these set of macros.

And to answer your question, you assume that J is lowercase unless it has a shift (⇧) next to it. At least that's what I did.

I actually got pretty far, but as I began using them things as you said, became unpredictable.

08%20PM

FWIW, my approach to problems like this is to use a modifier key with the main key I want to use. For example, I use OPT-J and OPT-K to trigger macros for UP and DOWN arrows. Most of the time I don't need the character that would normally be output by the OPTION key+.

I feel like it's a bit too soon to give up on these, especially since I can confirm this macro works perfectly for me, toggling the flag in the main Mail window and typing "s" in the composer:

Star.kmmacros (2.3 KB)

I would suggest importing that macro (which includes its macro group settings) and seeing if that does the trick for you as well. But even if it doesn't, there's another way you could make this group of macros work; by activating and deactivating them manually:

This way, you'll know that these macros are only in effect as long whenever the palette is visible, and when the palette is gone, you'll know the keyboard will function as normal. It's effectively a way to modalize groups of macros, and one I've found particularly useful for ones that use single keys as their triggers.

Here is another one that isn't working "Send Mail" ⌘Return isn't working for ⇧⌘D.

This works fine for me using the menu selection action:

But a macro like this that's meant to be used in the composer window can't be put in the same macro group that's meant to only be used in the mailbox window. This one needs to be in a typical Mail-specific macro group that's available in all windows:

53%20PM

The way I've been accomplishing this in other applications (haven't tried in Mail.app) is by checking whether the Show Substitutions command is enabled or not. If it's enabled (regardless of whether it's checked or not) then I'm editing text. If it's not enabled, then I can safely assume that single keys without modifiers are safe to use for triggers.

In this example, I want the Escape key to just type Escape when editing text, and to do something else when not editing text.

Hope this helps.

1 Like

Unfortunately it seems to be inconsistent. "Show Substitutions" is still enabled in Brave Browser even when not in an editing area:

image

1 Like

Any chance someone could share more of their kmmacros files from this thread? In particular, the j and k to go to next/prev messages would be great.

I'm new to Keyboard Maestro and this is the first thing I'm trying to do with it. The Star.kmmacros file above worked well for me, and I could use that template for an Archive action. But I'm at a loss finding information on how to go to next/prev messages in Mail. (Searching around did not help—the Applescript examples around the web for this type of thing are all super old and didn't work.)

I created some but they never worked well so I got rid of my Apple Mail to Gmail macros. Triggers without modifier keys don't work well. Also, welcome to this awesome Keyboard Maestro community!