Pause while idle.kmmacros (2.6 KB)
The problem appears to be that the IDLE() function, which seems to get its data from the HID subsystem in macOS, takes much longer to get values in macOS 27 than it did in macOS 26. Here's a modified version of your macro that displays the actual idle times (and only uses local variables) while running and when done:
Pause while idle - revised Macro (v11.1.1)
Pause while idle - revised.kmmacros (3.2 KB)
If I run that on macOS 26, here's what I see once the macro exits after moving the mouse:
Running that same macro on macOS 27, and after a bunch of wicked fast mouse movement and keyboard clicking, which eventually got the macro to stop, here's what I saw:
Notice how much slower—40 times slower!—the idle timer is on macOS 27 than in macOS 26. To work around this problem, which I strongly suspect is at the OS level and not the Keyboard Maestro level (@peternlewis can confirm how
IDLE() gets its data), I added disabled pause as the first command in the macro.
Enable that first action, run the macro, and it works as expected, exiting as soon as you move the mouse or type a key:
The downside is the need to wait a second to record the idle timer. Unless someone else has a better idea, though, I'm not sure how else to get around the slower response time in macOS 27.
-rob.
To be clear, a slower response time in macOS 27.2 -- this isn't an issue in 27.0.1
Out of interest, do you get any better results from either a shell Action or Terminal?
ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'
I can't get this macro to terminate, no matter how fast I move the mouse, with or without the initial 1 second pause. Running on a MacMini M4.
Weird, it terminates instantly for me with the pause. Try changing the initial delay length? Also, what time do you see for the old_idle variable?
-rob.
On my macOS 26 Mac Studio, I get .069 seconds. On my macOS 27 MacBook Pro, I actually get a faster response, .043.
Weird.
-rob.
Can you give this a go? It'll show average call time for IDLE():
IDLE() Time Test.kmmacros (3.3 KB)
For me, having just updated to 27.2:
...so no delay at all.
2.02243
Same, no delay. What the heck is going on?
-rob.
It looks like IDLE() is getting something different to ioreg's HIDIdleTime.
Here's a macro that logs both those plus the starting value:
Pause while idle copy (Nige version).kmmacros (4.9 KB)
...and when I run it then move the pointer:
...you can see the macro should end on the second loop according to HIDIdleTime, but not by IDLE().
I'd also note that if you don't interact for a while the two values track (allowing for the delay during execution) -- until you do something...
Why this is happening is well beyond my pay grade ![]()
I see the same thing you do, and agree it's also beyond my pay grade. Hopefully Peter will have something to say on the matter :).
-rob.
Mine too. And to think, I used to be the SVP SW at Apple!
The API used to determine the time since the last UI action is:
CGEventSourceSecondsSinceLastEventType(kCGEventSourceStateHIDSystemState, kCGAnyInputEventType)
I checked in 27.2 and yes, it does seem a bit odd.
The IDLE function does not take any time to compute (much less than the execution speed of Keyboard Maestro actions which is 0.001s per action).
However it does appear to give values that are noticeably higher than strictly accurate.
I used this simple sequence:
And as can be seen (in Sequoia) the results are about 0.002s to execute the second two actions, and IDLE time after clicking the Run button of around 0.001s.
But in 27.2, the result is variable and anywhere up to about a second.
However, that said, the only really legitimate use for the IDLE() function is to tell that the system is sufficiently idle, for example Pause Until IDLE() > 10 and that sort of usage will still work fine.
Sorry Peter, “Pause Until IDLE() > 10” did not work for me on 27.2.
Background: I had been using IDLE() to control activities for a cron job I had set up as a macro. It ran every 5 minutes, accumulating idle time. Depending on the state, it could kick off my custom screensaver depending on a user specified time interval, and then, later, if the screensaver had been running for different user specified duration, it would turn off the screen. I had to rip out all that code when IDLE() stopped working. I THINK functions like "Pause While IDLE" (so I could turn it on),and "Pause until NOT IDLE" (So I could turn it off). I could turn the display off if I the screensaver had been running for the user-specified time and it the system was still IDLE. Periodically running the cron job using only a constant frequency as KM implements it, let me to very complex logic in the cron job.
When I run this in Terminal, I see very fast response:
for i in {1..50}; do ioreg -c IOHIDSystem -d 4 | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'; sleep 1; done
This works.
So, are your suggesting that using this code as a base, I should create my own version of an IDLE() function?
Yes, that's what I was originally thinking, but with that approach and with IDLE(), my testing led to some false positives.
Here's an approach that is responsive and robust on my system...
Download: Pause while idle - @_jims.kmmacros (13 KB)
Macro-Notes
- Macros are always disabled when imported into the Keyboard Maestro Editor.
- The user must ensure the macro is enabled.
- The user must also ensure the macro's parent macro-group is enabled.
System Information
- macOS 27.2 (26B123)
- Keyboard Maestro v11.1.1
Despite my comparing their times earlier, HIDIdleTime and CGEventSourceSecondsSinceLastEventType (behind KM's IDLE()) are different things.
HIDIdleTime is reset by kernel-level hardware events, CGEvent... by WindowServer events (including simulated events like KM keystrokes and mouse movement). So whether you can use one as a replacement for the other will depend on what you are doing.
It's working fine here, as long as you read it as "pause until idle for about 10 seconds".
Problem seems to be a lag between interaction and WindowServer resetting the idle counter. Consider the following:
Idle Lag?.kmmacros (5.6 KB)
Which for me gives:
It looks like a 0.4s pause doesn't give long enough for WindowServer to reset the idle counter before it is tested via IDLE(), but a 0.5s pause does.
So a macOS 27.2 quirk/bug -- do you still have contacts?
Otherwise cross your fingers for a point-release bug fix and/or rewrite to use HIDIdleTime where that's a suitable swap.
Possibly stupid question: Is this supposed to terminate?
On my system, it loops forever, even after mouse moves or key clicks.
Yes. On my system it calls itself until the mouse/trackpad is moved or a key is pressed. At that point, it displays the No longer idle message.
Here is the diagnostic information I see when I trigger it, wait momentarily, then move the mouse.
I'm using:
• Keyboard Maestro 11.1.1
• Golden Gate 27.2 (26B123)/MacBookPro18,2












