Is there any way to tell if the screen is locked?

I’m aware of the SCREENSAVER() function, which “returns 1 if the screen saver is running, or the display is sleeping or locked.” But does anyone know of a way to check whether the screen is locked?

I ask because if I knew that the screensaver was running but the screen wasn’t locked, I could use the “Wake Screen” / “Stop Screen Saver” actions before UI functions to ensure that they’re able to run even if the screensaver was on.

On the other hand, if there’s no way to tell if the screen is locked, then presumably those “Wake Screen” / “Stop Screen Saver” actions would fail in that situation. So I’m curious about whether there might be a way to check if the screen is locked—so at least I could ensure that those functions could fail gracefully if I were to use them.

— Ashley

What is the difference between the display and screen being locked?
Aren’t they one and the same?

IAC, to be sure, you might just always have that action. AFAIK, the Wake Screen does NOT have a failure mode, so it should not stop your macro if the screen/display is already awake.

What is the difference between the display and screen being locked?
Aren’t they one and the same?

I’m not aware of any differences between the screen being locked and the display being locked—I think those are two different ways of saying the same thing. (Is that what you’re asking?)

IAC, to be sure, you might just always have that action. AFAIK, the Wake Screen does NOT have a failure mode, so it should not stop your macro if the screen/display is already awake.

Right. In short, I foresee three possibilities when it comes to running UI code:

  1. The screen is in its normal state: The screensaver isn’t running and the screen isn’t locked.

  2. The screensaver is running and/or the display is asleep—but the screen isn’t locked.

  3. The screensaver is running and/or the display is asleep—but the screen is locked.

When doing UI stuff, it’ll run fine in scenario 1 or scenario 2 (as long as you run Wake Screen / Stop Screen Saver first). But it’s that third scenario that I don’t know how to detect.

— Ashley

How about doing something like:

  • If calculation SCREENSAVER()
    • Wake Screen
    • Pause
    • If calculation SCREENSAVER()
      • Complain
      • Cancel This Macro
1 Like

Ah—I suppose that could work! If I might ask, what makes the Pause in the middle necessary? (Does Wake Screen run asynchronously?)

P.S. If I might put in a request, I don’t suppose there could be a LOCKED() function for Keyboard Maestro 8.x? :sunny:

— Ashley

I don’t know. It is the sort of thing the system is highly like to “hand off to some other process”, and the sort of thing that is likely to take some time to happen. So the pause may well be necessary.

If I can figure out how to tell whether it is locked, I will, but I suspect I can’t - I suspect it sort of happens outside the user space.

1 Like

Like most systems/languages with a variety of commands/actions/options, often the best approach is trial and error. Just keep trying stuff until you find something that works.

How do you call the SCREENSAVER() function at all? I need to figure out if the screensaver is running or not. Thanks!

With a calculation:

Keyboard%20Maestro%20Export

Will be 0 or 1. (Wiki)

That worked! Thanks!