Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple Spolight search is not recognized as frontmost application #3794

Open
SamStuckey opened this issue Apr 28, 2024 · 2 comments
Open

Apple Spolight search is not recognized as frontmost application #3794

SamStuckey opened this issue Apr 28, 2024 · 2 comments

Comments

@SamStuckey
Copy link

Description

  • Apple's Spotlight feature does not register as 'frontmost application'
  • Whatever is the 'frontmost application' at the time of a spotlight window opening remains the active 'frontmost application'

Examples

Showing EventViewer not responding to Spotlight
Screenshot 2024-04-28 at 9 11 13 AM

Showing EventViewer tracking Finder as frontmost application before opening spotlight
Screenshot 2024-04-28 at 9 12 17 AM

Showing Event Viewer still tracking Finder as frontmost application with spotlight open again
Screenshot 2024-04-28 at 9 12 23 AM

To Reproduce

  1. Open EventViewer
  2. Open Spotlight with Cmd+Spacebar shortcut

My Goal

I want to map ctrl+n and ctrl+p to my up and down arrows inside of spotlight. So far the best I've come up with is a global mapping with an exception for my terminal programs (Already using those shortcuts for VIM stuff). This works most of the time, unless I open spotlight on top of a terminal window. Terminal (Iterm2, actually) stays active as my frontmost application, disabling my up / down keying within spotlight.

My current config to accomplish this goal

Again, this works unless I try and use the spotlight search on top of a terminal window (which I do often)

  {
    "description": "Use n & p as up and down arrow keys",
    "manipulators": [
      {
        "conditions": [
          {
            "bundle_identifiers": [
              "com.googlecode.iterm2",
              "com.apple.Terminal"
            ],
            "type": "frontmost_application_unless"
          }
        ],
        "type": "basic",
        "from": {
          "key_code": "n",
          "modifiers": {
            "mandatory": [
              "left_control"
            ]
          }
        },
        "to": [
          {
            "key_code": "down_arrow"
          }
        ]
      },
      {
        "conditions": [
          {
            "bundle_identifiers": [
              "com.googlecode.iterm2",
              "com.apple.Terminal"
            ],
            "type": "frontmost_application_unless"
          }
        ],
          "type": "basic",
          "from": {
            "key_code": "p",
            "modifiers": {
              "mandatory": [
                  "left_control"
              ]
            }
          },
          "to": [
            {
              "key_code": "up_arrow"
            }
          ]
      }
    ]
  },

Ideal Outcome

  • When open, Spotlight registers as frontmost application with a unique bundle_identifier that I can use to lock in behavior specific to that spotlight window., e.g.
  {
    "description": "Use n & p as up and down arrow keys",
    "manipulators": [
      {
        "conditions": [
          {
            "bundle_identifiers": [
              "com.apple.Spotlight"
            ],
            "type": "frontmost_application_if"
          }
        ]
        ...
      }
    ]
  },
@temp4422
Copy link

Same.
Also this mentioned: #1428 and #1982

@dzirtusss
Copy link

I managed to mitigate this problem in a following way:

  1. mapped Cmd+space to set mode-spotlight var
  2. mapped Esc with mode-spotlight: on to a) deactivate var b) send 2X Esc
  3. mapped Enter with mode-spotlight: on to a) deactivate var b) send Enter

Which basically keeps spotlight state in that mode-spotlight var.

That overall works for me. Problem is 2x Esc as one escape may be not enough to close spotlight with results (it resets instead), but... var tracking is lost. So, sending 2x Esc to close spotlight always fully (not a big deal).

When it very rarely does not work, I just have to click more escapes to clean everything.

My use case is a bit different - I want to leave vim mode in one app, and make hjkl back to normal in spotlight. But I guess overall approach to your case may be same.

Some snippet if it may help:

{
            "conditions": [
                {
                    "bundle_identifiers": [
                        "^com\\.tinyspeck\\.slackmacgap$"
                    ],
                    "type": "frontmost_application_if"
                },
                {
                    "name": "slack-vi-mode",
                    "type": "variable_if",
                    "value": true
                },
                {
                    "name": "slack-vi-mode-spotlight",
                    "type": "variable_unless",
                    "value": true
                }
            ],
            "from": {
                "key_code": "spacebar",
                "modifiers": {
                    "mandatory": [
                        "command"
                    ]
                }
            },
            "to": [
                {
                    "set_variable": {
                        "name": "slack-vi-mode-spotlight",
                        "value": true
                    }
                },
                {
                    "key_code": "spacebar",
                    "modifiers": [
                        "command"
                    ]
                }
            ],
            "type": "basic"
        },
{
            "conditions": [
                {
                    "bundle_identifiers": [
                        "^com\\.tinyspeck\\.slackmacgap$"
                    ],
                    "type": "frontmost_application_if"
                },
                {
                    "name": "slack-vi-mode",
                    "type": "variable_if",
                    "value": true
                },
                {
                    "name": "slack-vi-mode-spotlight",
                    "type": "variable_if",
                    "value": true
                }
            ],
            "from": {
                "key_code": "escape"
            },
            "to": [
                {
                    "set_variable": {
                        "name": "slack-vi-mode-spotlight",
                        "value": false
                    }
                },
                {
                    "key_code": "escape"
                },
                {
                    "key_code": "escape"
                }
            ],
            "type": "basic"
        },
        {
            "conditions": [
                {
                    "bundle_identifiers": [
                        "^com\\.tinyspeck\\.slackmacgap$"
                    ],
                    "type": "frontmost_application_if"
                },
                {
                    "name": "slack-vi-mode",
                    "type": "variable_if",
                    "value": true
                },
                {
                    "name": "slack-vi-mode-spotlight",
                    "type": "variable_if",
                    "value": true
                }
            ],
            "from": {
                "key_code": "return_or_enter"
            },
            "to": [
                {
                    "set_variable": {
                        "name": "slack-vi-mode-spotlight",
                        "value": false
                    }
                },
                {
                    "key_code": "return_or_enter"
                }
            ],
            "type": "basic"
        },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants