Periodic trigger for when screen awake?

I have a macro I want to run every 10 minutes or so when my macbook is unlocked (lid my be down and plugged in or open) that starts a timer using shortcuts. I have tried "Periodically while logged in" trigger but I think it may be triggering occasionally when the lid is closed and no monitor is plugged in (when it should be asleep).

Is there a way to check if this is happening? Also is there an alternative trigger or if condition that has something to do with activity?

To check if it has run or not, just add a Log action to your macro:

image

You can then open the log file folder (Help > Open Logs Folder), then open the Engine.log file in a text editor and look for your log entries. Each will be time/date stamped, so you can see exactly when it ran.

(This info is actually already in the log—you'll see an entry when your macro triggers—but I find it easier to use my own text to make searching simpler.)

As for the trigger, I don't think there's another trigger, but you might be able to use one of the monitor resolution tokens, like %FrontWindowFrame%. In fact, maybe put that in your Log command:

Text: Screen 1 is %FrontWindowFrame%.

Then you can see not only when it ran, but what Keyboard Maestro thought the display resolution of the main display was. Depending on the results, you could use an If-Then on a Text condition, where %FrontWindowFrame% contains or does not contain some value specific to when the external is attached.

That's mostly conjecture, though, until you know if it's really running with the screen closed and nothing attached—so add the Log action and see what happens.

-rob.

2 Likes

Thank Rob, great idea.

So I added the log element and here is what happened this morning.

Note, as you can see the macro is set to run only from 7am. I opened my laptop at around 8:10.

2024-04-18 07:14:44 Execute macro “dis AUTO on” from trigger Every 8 minutes between 7:00-17:30 Monday-Friday
2024-04-18 07:14:44 Log: Screen 1 is 0,1117,0,0
2024-04-18 07:16:00 Execute macro “dis AUTO on” from trigger Every 8 minutes between 7:00-17:30 Monday-Friday
2024-04-18 07:16:00 Log: Screen 1 is 0,1117,0,0
2024-04-18 07:23:59 Execute macro “dis AUTO on” from trigger Every 8 minutes between 7:00-17:30 Monday-Friday
2024-04-18 07:24:00 Log: Screen 1 is 0,1117,0,0
2024-04-18 07:51:45 Execute macro “dis AUTO on” from trigger Every 8 minutes between 7:00-17:30 Monday-Friday
2024-04-18 07:51:45 Log: Screen 1 is 0,1117,0,0
2024-04-18 07:56:00 Execute macro “dis AUTO on” from trigger Every 8 minutes between 7:00-17:30 Monday-Friday
2024-04-18 07:56:00 Log: Screen 1 is 0,1117,0,0
2024-04-18 08:20:00 Execute macro “dis AUTO on” from trigger Every 8 minutes between 7:00-17:30 Monday-Friday
2024-04-18 08:20:00 Log: Screen 1 is 206,80,1522,995
2024-04-18 08:28:00 Execute macro “dis AUTO on” from trigger Every 8 minutes between 7:00-17:30 Monday-Friday
2024-04-18 08:28:00 Log: Screen 1 is 206,80,1522,995

So it does run when the screen is down*. Interesting to see the screen resolution there as 0,1117,0,0 and how sporadic the timings are of the executions.

*Actually the screen was not fully closed, it was open very slightly so will retest when full closed and report back with that.

Hmmm, so it seems to be a bit inconsistent when it runs but this was one entry with the lid fully closed:

2024-04-18 10:11:22 Execute macro “dis AUTO on” from trigger Every 8 minutes between 7:00-17:30 Monday-Friday
2024-04-18 10:11:23 Log: Screen 1 is 0,0,0,0

So I think I will look at using the If condition based on the window frame as suggested.

You are logged in, so it's a question of whether the laptop is actually asleep or not. Especially true if you have Power Nap enabled, which it is by default. Never tried myself, but perhaps that wakes the machine enough that KM can run scheduled macros?

Since it looks like it does run when the lid is down, whatever the reason, let it trigger but start the macro with a check to see if the lid is closed -- cancel the macro if it is:

image

Thanks. Yes exactly it is logged in.

Will add that statement to the macro. :+1: