2

How can I switch among application windows using Cmd/Opt + 1/2/3... etc, like on Unity or KDE?

Why? This is especially handy if you often switch among the same few apps, e.g. a browser, a file manager and an IDE, but also have other apps open, so Alt+Tabbing to the desired window would take more time.

That keyboard shortcut saves me probably 5 seconds per minute on the average, so ~40 minutes a day, and it's supported by Windows as well.

I tried using the native Automator and Keyboard shortcuts in System settings, but the shortcut is only picked up in some applications (e.g. Automator, Webstorm), but most applications seem to consume it before it reaches the system.

To create the shortcut with Automator:

  1. ⌘+Space and launch Automator
  2. Choose "Quick action"
  3. Set the "Workflow receives current" to no "input"
  4. In the panel on the left, filter for the Run Shell Script Action and double click it
  5. In the Run shell script text area, replace cat with the command to run your application, e.g. open -a "Google Chrome".
  6. File -> Save and name your shortcut, e.g. Chrome launch/switch to

Assign the keyboard shortcut

  1. ⌘+Space and type keyboard shortcuts to access it in System Settings
  2. Click Services -> General and you'll see your newly created shortcut
  3. Double click none and press your hotkey combo, e.g. ⌘+1
  4. Click Done

I'm looking for a more reliable solution than the system's Keyboard shortcuts.

  • 2
    You can switch Spaces with Ctrl/Number. If you put one app on each Space, you've got it. [Doesn't work for fullscreened apps]. – Tetsujin Apr 06 '23 at 08:02
  • @Tetsujin: I don't want the whole animation of switching spaces. I want to quickly switch for example between my IDE and the browser when I look up some reference information. – Dan Dascalescu Apr 13 '23 at 17:05
  • 1
    There's no native way to do what you want. – Tetsujin Apr 13 '23 at 17:45
  • In contrast with the open-source Linux world, it feels frustrating and powerless to be unable to provide feedback to Apple about this. – Dan Dascalescu Apr 21 '23 at 13:20
  • @DanDascalescu The type of feedback you can give via the links at the bottom of https://www.apple.com/contact/ ? – nohillside Jul 03 '23 at 19:31
  • @nohillside: I was looking for an issue tracker, like Google's, or Ubuntu's, or KDE's etc. Apple doesn't have a public one. The closest to that concept seems to be a community forum, https://discussions.apple.com/community/macos (which isn't linked on that contact page). – Dan Dascalescu Jul 04 '23 at 04:28
  • discussions.apple.com is a support site. Apple doesn‘t have a public issue tracker. – nohillside Jul 04 '23 at 04:51

1 Answers1

3

Karabiner-Elements can be used to run an open shell command. It'll open it if the application is closed, and focus if it's already open. If you create cmd-numbers.json in ~/.config/karabiner/assets/complex_modifications/, you'll see new rules in Karabiner under Complex modifications | Add rule:

{
  "title": "Launch apps with Cmd+<number>",
  "rules": [
    {
      "description": "Finder",
      "manipulators": [
        {
          "from": {
            "key_code": "1",
            "modifiers": {
              "mandatory": "command"
            }
          },
          "to": {
            "repeat": false,
            "shell_command": "open -b com.apple.finder"
          },
          "type": "basic"
        }
      ]
    },
    {
      "description": "Firefox",
      "manipulators": [
        {
          "from": {
            "key_code": "2",
            "modifiers": {
              "mandatory": "command"
            }
          },
          "to": {
            "repeat": false,
            "shell_command": "open -a Firefox"
          },
          "type": "basic"
        }
      ]
    }
  ]
}

The -b flag means bundle ID. You can also use open -a Finder.app.