Defocus other windows when Spotlight windows loaded

Is it possible to defocus other windows when Spotlight windows loaded or at least let KM know that Spotlight search window is active?

You can assign calling Spotlight window using macro by so-called trigger key "Opt+Space" since "CMD+Space" cannot be triggered using shortcut key in KM. So in this way, you can do whatever you need using the macro

1 Like

I need KM to do some actions while spotlight window is open. And stop doing it when it hides. Will it help?

what kind of actions you need to do while spotlight window open?

The problem is that the Spotlight window isn't a "real" window. Even when you activate it in the OS, the frontmost app's window remains in focus. Looking at it with Accessibility Inspector, and watching for processes in Activity Monitor, I don't see any way you can detect the appearance of the window.

So here's a way around it, sort of, though it has issues:

Download Macro(s): Spotlight detector.kmmacros (4.5 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 14.7
  • Keyboard Maestro v11.0.3

To make this work, use the macOS Settings panel to change Spotlight to Shift-Control-Space. When you press Command-Space, this macro triggers and launches Spotlight (so it knows the Spotlight window is onscreen).

You can then do whatever you need to do in the macro, until the Return key is pressed, which closes the Spotlight window and processes whatever was typed there.

The big caveat: This fails badly if you press Escape twice to close Spotlight. If you press it once (to erase input), then hit Return, all is fine. But if you press it twice, the macro will still be waiting for a Return key—so you have to hit Return to cancel the macro, but that Return will also get sent to the frontmost app, because the Spotlight window is gone.

There are probably some tricky ways around this, but I don't have the time to spend on figuring those out. Maybe set an action timeout on the "Until" action, long enough to cover whatever you need to do, but short enough that it will time out and stop running?

Anyway, hope that's enough to get you started on possible solutions.

-rob.

1 Like

It's easy and quick to check periodically if the Spotlight icon appears in its usual place (the Spotlight window always appears in the same place). This example below should solve the problem by checking once per second. It's possible to check more than once per second, but I wanted to keep this macro simple: (of course, he will have to change the image's area coordinates and the image well itself.)

He didn't say what actions he wanted to perform, so I had no idea how to incorporate that in my solution.

No, it doesn't. It appears in the same place as it last appeared, and that's a big difference: I move mine around all the time. So I had to try to detect the magnifying glass on the entire screen, and it failed badly for me, regardless of fuzziness level.

That's why I took the approach I took. But if they don't move their Spotlight window around, your method should work.

-rob.

I'll check it out, thanks!

The problem is that this image is not really the same. It changes its color during day.

That's fixable. Of course, I can't fix it since you haven't provided details of the colour changes.

Yes, I knew that, and I agree, but the person asking never actually said he needs the macro to work across the entire screen.

I have found the old thread about it. I need it for the macro that makes return open the folder/ files but leaves other return functions intact.

I have in fact made it work but with the significant delay as it had to check 6 screenshots during the execution.

just one magnifiyng glass screenshot didn't work.

I've tried to create another macro, which will disable the macro that changes the return function when I press command+space and turn it on again when I press return or escape but for some reason it didnt' work or work very unstable.

Are you able to post the macro?

-rob.

Why? What are you trying to achieve (or stop!)?

Other windows are "defocused" when the Spotlight search window is active, at least as far as typing and similar contextual commands (eg ⌘C and ⌘Z) are concerned. Some commands will pass through to the active app (eg ⌘` will cycle app windows) but leave the search window active, others (like mouse clicks) will cause the search window to close.

Open or rename [Finder].kmmacros (6.0 KB)

It doesn't contain the Spotlight screenshots as I deleted them, when I though it's too slow that way anyway.

I want to make the attached macro to ignore Spotlight

They accept Return with my macro

I'm afraid I still haven't a clue what you mean.

Regardless, if you want to check if a Spotlight search window is open:

image

Just a thought, though. Do you mean the Spotlight window that you get on your screen after you've clicked the Spotlight magnifying glass icon in the menu bar, or do you mean the Spotlight search field of a Finder window? The above tests the first.

2 Likes

I mean the floating window, not the Finder's one. Thanks! I will check it out immediately!

It worked! Finally.

The first part was created by @griffman. I have incorptorated the Spotlight part from you.
Return to Open Folder or FIle.kmmacros (7.5 KB)

In general I am trying to make Macos use enter for the opening files and folders. Current macro forks fine but adds delay. Seems there is no way to change this with no consequences. Why didn't allow the user to change it?