[SOLVED] Check if Raycast's "Spotlight" Is at the Front

A while ago I was able to find help with Raycast quitting:

Now I can't seem to find a way to check if the "spotlight" window is present or not. Using UI Browser, I get this when I hover over it:

application "Raycast"
	system dialog (window 1)

But if I use this, it doesn't work:
Raycast - Detect if Active.kmmacros (22 KB)

Keyboard Maestro Export

It always shows me the "True" notification, even if the "spotlight" is not present

Some windows can be present but not visible. Try the following in ScriptEditor, with and without the Raycast "spotlight" window open:

tell application "System Events" to return every window of process "Raycast"

...and see what you get.

Thing is, when I click outside Raycast's window, it closes it, so I can't press Play inside Script Editor...

When Raycast is closed, the output it just {}
Is there a way to schedule the script to run a few seconds after I hit Run?

delay 5 -- 5 second delay
tell application "System Events" to return every window of process "Raycast"

Ok so without it open, I get {}
When it's open:

{window 1 of application process "Raycast" of application "System Events"}

So you should be able to replace your entire AppleScript in the first action with:

tell application "System Events" to return exists window 1 of process "Raycast"

...and hope that explicitly returning the value solves the problem.

If that doesn't work it'll probably need someone with Raycast installed to troubleshoot.

1 Like

Awesome! It worked! Thank you so much for your help! :slight_smile:

Raycast - Detect if Active.kmmacros (22 KB)

Keyboard Maestro Export

1 Like

FYI (11 months later), this approach will work most of the time, but if any other Raycast window is open, it will return a false positive. Specifically, it will falsely return true when the search window is NOT open if either

  1. The Raycast settings are open; and/or
  2. The Raycast AI Chat is open


Original version behind cut to avoid confusion

I spent a lot of time trying to find a reliable way to verify that it's the SEARCH window that's open, and so far, the best solution I've found is to look for a Raycast window that has the same height as the search bar. I've attached it here in case other people come looking for answers in the future.

Raycast - Detect if search is open.kmmacros (2.3 KB)


Here's the latest version I use. Unlike the previous version, this one will also work if you use the default window mode instead the compact mode (or if you use the compact mode but have expanded the window to the full size because you're using an extension or have started searching for something). I use it as a subroutine, so that's what I'm uploading here. The dimensions for all the relevant windows are also included in a comment so you can tweak the script if/as needed.

Is Raycast Active? (subroutine).kmmacros (4.2 KB)

1 Like