Closed alex-grover closed 2 years ago
I like the idea. Or I did, until I played around with it. Being active for a set time is a feature of caffeinate
itself. That’s a tool that ships with macOS and which both Workflows use. The way caffeinate
knows to stay on is via a -t
(timeout) option given in seconds.
If you’ve ever built a timer in code, you’ll know waiting for a set number of seconds isn’t a good way to do it. Due to the nature of how computers work, being under load or other factors will make your timer out of sync. The correct (and more complicated) way of doing it is to periodically check the system clock to see if the desired time has elapsed.
I checked how Caffeinate Control does it, and it’s the naïve way of assuming one second since caffeinate
has started equals one fewer second remaining for it to be done. That’s not something you can trust.
I just did a bunch of tests with caffeinate
and its timer slows down by about 10%. a timeout of 60 seconds takes ≈ 66 seconds. 30 → 33, 90 → 99. It’s weird how consistent the delay is, to the point I’m wondering if it’s a bug.
Now, it’s not a big deal if you ask for you computer to not turn off for 2 hours and it takes 2 hours and 12 minutes to do so, but it is a problem if you’re told you still have 17 minutes left when you only have 5. I can think of ways to make the timer more accurate, but that entails using more system resources to kill it at the right time. I don’t think that’s worth it, seeing you’re the only one who has ever asked for this feature.
I’ll close the issue though I’m not saying “no” yet. I’ll think further on how big of a deal this really is in practice, but I don’t like the thought of giving out incorrect information.
makes sense. not hugely important to me, but figured i would suggest. FWIW i've used Caffeine Control for years and have never noticed any discrepancies between the timer and the caffeinate process
It was a good suggestion. The consistent 10% may be a Monterey bug; I’ll investigate further.
Was poking around the Workflow for other things and decided to implement the feature. I’m using the simple approach, so let’s see how it goes. One particular difference is that instead of saying how many minutes remain, it lists the time at which it predicts it will turn off.
Sounds great! Let me know if I can help with testing or anything else!
No need, thank you, the Workflow is already released so just enjoy the feature! Unless something in wrong, in which case a bug report is appreciated.
Setup info
Description of issue
I've been using Caffeine Control for a while now, but saw your workflow and wanted to switch to something that's actively maintained. One feature they have that's nice is that the display shows how long is left when you type the command: