Spotlight Does Not Respond to Window Move and Resize Commands

I created a macro to centre windows.

The macro works for all windows that I tested it on EXCEPT Spotlight where the macro does NOT move the Spotlight “bar”. Is this normal, is there a way to fix this?

Please show me how to fix this.

Thank you.


Edit 2021/12/13 09:18 CST: removed unnecessary tell-block... -ccs


Hey Joel,

The Spotlight window is a floating system window that Keyboard Maestro doesn't see.

Use AppleScript:

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/12/13 06:01
# dMod: 2021/12/13 09:17
# Appl: Spotlight, System Events
# Task: Reposition and Resize the Spotlight Window.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Spotlight, @System_Events, @Reposition, @Resize, @Spotlight, @Window
--------------------------------------------------------

tell application "System Events"
   tell application process "Spotlight"
      tell window "Spotlight"
         set {position, size} to {{380, 172}, {680, 430}}
      end tell
   end tell
end tell

--------------------------------------------------------

List Windows Keyboard Maestro Can See v1.1

-Chris

1 Like

Chris, I appreciate you clarifying that the behaviour towards spotlight is normal.

I thank you for the script to control it, I will look into ways of integrating the AS into by KM macro so that I only need one entering macro.

Thanks.

1 Like

Chris, when I try running the script I get an error message that it cannot see Spotlight when trying to execute the repositioning, do I need to activate System Events somewhere?

Thanks.

I think not – System Events should be activated by the tell block. Although I'm testing on Mojave and don't know what mischief Apple has done with later versions of macOS.

  • What version of macOS are you using?
  • What version of Keyboard Maestro?
  • How are you running the AppleScript?
  • Are you running an English system?

The Spotlight window won't resize, before it has been populated at least on Mojave.

It's possible Apple has change some syntax here or there.

-Chris

Chris, in response to your questions the answers are:

  • Catalina, 10.15
  • Keyboard Maestro 10.0.2
  • Apple Script running through Script Debugger after being compiled
  • Yes on English.

Spotlight should reposition as it does using Moom.

Thanks.

Yep @Joel, as written in my DM:

1 Like

Now that is interesting.

When I went into Privacy / Accessibility there as no System Events icon.

The problem now is how to add it because when I clicked on the + button and search for System Events nothing came up!

Great catch!

@Joel please insert as in gif:

2021_12_13_Support_1

I appreciate this...I can not find a way to increase the size of the gif so cannot see the folder...please either show me how to expand the gif OR what folder to drag and drop the file from...thx!

Right-click ⇢ Open the gif in a new tab ⇢ Zoom web page as desired.

For other instructions see this:

Finding Files on macOS

-Chris

1 Like

Thx! Stupid me!

Quick question...does / will KM recognize Spotlight as a frontmost application....the reason I ask is that I would like to update my Centre macro with an IF THEN ELSE statement depending on whether SPOTLIGHT is the frontmost application or not BUT before I do so I would like to know whether it can / can not work.

Thx!

The short answer is in post #2 above, KM cannot recognize the Spotlight window. But also in post #2 it showed a way for AppleScript running in KM to process that window. So I guess what you are now asking for is how to use AppleScript (not KM) to detect if the Spotlight window is visible.

Or if you don't want to use AppleScript, you could try the Find Image action to see if the Spotlight window is on the screen. But clearly AppleScript is the more professional way to do this.

@Sleepy, I wanted to use an if statement to test whether the front mist application was Spotlight and, if yes, then use the AppleScript to centre Spotlight all within one KM macro.

I suppose what I will now need to do is use an AppleScript with a KM macro to centre any front most application including Spotlight unless anyone has any better idea.

I would really like to avoid using AppleScript because every time I use AppleScript it defeats the purpose of KM.

Thanks.

I know what you want to do, but post #2 says that Spotlight's window is hidden from KM.

But I admit I'm not sure why KM can't see it if AppleScript can. I just trust cc who is almost never wrong.

KM has never claimed to be able to do everything. This is why it has hooks to other things like AppleScript, Javascript, Shell Scripts, etc. So it doesn't defeat the purpose to use those things. I wish KM could do everything, but for that to happen Apple would have to open some of its APIs for public (ie, KM) access.

Fair point and agreed!

Because Peter designed it that way.

Most users don't need to see non-application windows, and there are 3rd party tools to let more advanced users manipulate them if needed.

Personally I'd rather that Keyboard Maestro could see everything, but I think that might be a tech support nightmare for Peter.

-Chris

Fair point. I was not able to see that logic.