[SOLVED] Check Whether Raycast is Running

Raycast (Alfred is the same thing) when used as spotlight doesn't show up as an application that's upfront, so using the action to check if the Raycast app is upfront/activated won't work. I was testing it and it only fires the action when I actually open Raycast's preferences.

Is there a way to check this when it opens as spotlight?
For example for Keyboard Maestro, we can check if the Engine is running, which is separated from the Editor window. Can we check if the "engine" of Raycast is also running, or something like that?

Just change the application name in this: Is there any way for KM to know that Alfred is now the focused window? - #12 by martin

1 Like

Ok so I was able to "kinda" make it work by changing everything to "Raycast".
Now there's an issue and I'm not sure if in Alfred this also happens.
When I go to the Variables window I can see that when Raycast is active, it shows a long list of numbers like this, for example:

If I then press CMD+Space again to close Raycast, those numbers are gone. The issue is that if I instead use Escape to close it instead of CMD+Space, those numbers remain there (or if there were none, it remains empty). Any workaround?

I could say "if the variable is empty, force it have those numbers", thing is, I have no idea how to force that...

Any clue?

EDIT: I just tested it with Alfred and it does remove those numbers whether I use the shortcut or Escape, but there's another issue: if I click outside Alfred, it closes it but the numbers remain so next time I use the shortcut, it will start from where it left off so if there were numbers there, now when Alfred is activated, the numbers are gone.

It seems that both apps have their own issues when it comes to this approach...

I'm not sure what you mean. Are those numbers all in one variable in the prefs window? Can you post a screenshot?

Here's the bare bones of what you're trying to do, namely test for the Raycast window, as a macro:

Is Raycast Active?.kmmacros (20 KB)

Macro screenshot

1 Like

Yes, preferences window. But using your macro, that's no longer necessary anyway.

Ok I tried your macro. It's way simpler than the other one!
So it works if I always use CMD+Space to open it or close it, but 2 issues:
1 - It doesn't work if I use ESCAPE to close it
2 - It doesn't work if I simply click outside the window

So I tried something, let me know if this is a good approach.
Once the macro starts running, it keeps looping the AS, so it will keep checking if it's true. Once it turns false (closing the window, whatever way I do it), the loop will find that Raycast is no longer running and it turns false and when that does, it cancels the macro.

Raycast - Detect if Active.kmmacros (3.0 KB)

Keyboard Maestro Export

I tried it and it's running, so that's good!
Just wondering if it's ok to have it looping or if there's another way to approach it?

Give me some context about what you're doing with it, specifically. The screenshot you posted above is of a macro that repeatedly sets a variable to true until that variable is false. What is the purpose of that? Can I assume that you want other macros to behave differently, depending on that variable's state? If so, please give an example. Whether the AS loop is the best approach depends on what the other macros are doing. What I will say is that I do have some macros that behave differently depending on the result of that kind of AS, but I don't use a loop like that.

For example, I have a super handy macro that quits and relaunches the current app. It starts with an AS that detects windows of certain apps that KM can't detect on its own. If any of the apps referenced in the AS are detected, they will be quit and relaunched; if not, the macro will quit and relaunch the front app (detected normally by KM).

Relaunch Current App.kmmacros (52 KB)

Macro screenshot

As you can see, in this case I'm running the script at the start of the macro itself, rather than setting the variable externally. This is preferable to me because it means the AS only runs when needed rather than every time one of those 'undetected' app windows is visible.

Context: remember when you shared a macro using Alfred to move a selected finder file to a location that I search for inside Alfred?
Well right now I'm only using KM and Raycast. I have Alfred installed, but for now, at least with the free version of Alfred, I don't see anything that Alfred can do that Raycast can't so I don't want to rely too much on Alfred just for that single task so I'm converting it to Raycast. Now, I always like to use a Pause Until when it comes to certain actions, just because if my computer stops responding even for a second, I want the macro to still run so I'm trying to check if Raycast is running before going to the next action. Nothing fancy.

I can completely ignore the "false" section of the script and only rely on it being "true" and if so, move on to the next action.

So what you want is: pause until Raycast's floating window appears?

1 Like

Yes. At least in this particular case. I will keep that other macro with both options just for "educational" purposes :wink: