MacOS – Single Keyboard Maestro keyboard macro, but different action depending on active application

keyboardmacosshortcut

In Keyboard Maestro I want to create a list of keyboard shortcuts, and then under each keyboard shortcut an action to be performed on a per-app basis if that application is active.

For example, when I press Left, I always want to switch to the tab to the left.

I want this action to apply in Chrome, Safari, Xcode, and other apps. The actions in each app may have different menu bar item names, but I want to save them as a single Keyboard Maestro macro for easier grouping.

The Select or Show a Menu Item action menu item titles I need to activate are:

  • Chrome: "Select Previous Tab"
  • Safari: "Show Previous Tab"

Keyboard Maestro window

But when I set up Keyboard Maestro as seen in the screenshot, this activates all of the actions. Regardless of which app is active, both Chrome and Safari run that action.

How can I set it so that only the active application performs the action, and give it a list of all possible application/action pairs?

Best Answer

A fairly simple solution: if-then-else actions. See this one for Finder: A Keyboard Maestro if-then-else action that only works if Finder is at the front.

If you nest each application-specific action within an If statement that checks whether the relevant app is at the front, it should work.