ACTION: Switch Case Based on FrontMost App

ACTION: Switch Case Based on FrontMost App

Download:

Switch Action based on FrontMost App.kmactions (2.4 KB)

NOTE: This file is for an Action, NOT a Macro.

Use Case

  • Generally it is best to put your app-specific Macros in a Group which limits activation to the app of interest.
  • But sometimes, you need to handle multiple apps within the same Macro.
  • This Action is designed for those cases.
  • Make sure the Macro is in a Group where all of the Apps of interest are in the "Available List" in the Macro Group definition.
  • For details, see:
    https://wiki.keyboardmaestro.com/action/Switch_or_Case

Install Instructions

  1. Download the Action file.
  2. In the KM Editor, select the Macro where you want to use this Action
  3. Select the existing Action, or a "No Action" input area, where you want the new Action to appear.
  4. Goto File > Import Actions..., and select the file you just downloaded.
  5. It will appear in your Macro.

You can repeat Steps 2-5 for other Macros if you wish. You can also just copy/paste the Action to a new Macro, or a different location in the existing Macro.


SETUP INSTRUCTIONS

Change, replace, or delete each CASE to match the Name of the App.

  • If you use the "is" condition, then it must match the app name exactly.
  • However, you can use the "matches" condition to provide a RegEx pattern to match against the app name.
  • There are other conditions you can also use.
  • For details, see:
    https://wiki.keyboardmaestro.com/action/Switch_or_Case

7 Likes

Thanks. I just don't understand why there is a "otherwise" condition at the end?
Does it to prevent the macro loop forever?

Since I don't know if the macro will stop / exit as soon as the first condition is met so I put a "break the loop" action along with every switch condition. -_- it looks somehow silly.

Please see the Switch or Case action in the KM wiki

There is no loop.
As soon as one Switch Case meets the criteria, the Actions in it are executed, and then the Switch block is exited.
You do not need a "Break from loop"

The purpose of the "Otherwise" case is a catch-all if NONE of the above Cases are met.