Key Mapping for specific apps in Mac

Scenario: Keymapping for specific apps in Mac.

For example, Windows and Mac use control/ command keys differently, it becomes annoying when using Microsoft Remote Desktop on Mac doesn’t provide a self-contained working environment, it often jumps to other mac apps easily. Map the mac command key to control key sort out the problem.

  • After installation, allow this 3rd party app to make system changes: System Preferences > Security & Privacy button > Allow. If not working, try close Chrome and MagicPrefs if installed. cc steps.

  • In order to map keys only for specific apps, we need the app bundle ID: Go to the application folder (e.g. /Applications/) mdls -name kMDItemCFBundleIdentifier -r Microsoft\ Remote\ Desktop\ Beta.app Then got "com.microsoft.rdc.osx.beta"

  • Create a new json script under ~/.config/karabiner/assets/complex_modifications/, Here is my sample.json:

{
  "title": "Remote Desktop new",
  "rules": [
    {
      "description": "Map left command to left control",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "left_gui",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_control"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "com\\.microsoft\\.rdc\\.osx\\.beta"
              ]
            }
          ]
        }
        
      ]
    }
  ]
}
  • The new rule should pop in the perference/ complex modification tab: screen shot 2018-06-20 at 11 20 18 am

  • Enable the new rule: screen shot 2018-06-20 at 11 20 09 am

  • Debug: Karabiner has a handy tool Karabiner-EventViewer to track all inputs, check the eventType of the desired keys; and bundle names mentioned in the previous step. screen shot 2018-06-20 at 11 28 02 am Also disable/ enable the new rules to make sure it’s applied.