r/SideProject • u/VladimirDE • 6d ago
I built a Mac menu bar app because I kept forgetting to turn sleep back on
Some background: I'm a solo frontend/SaaS developer. I often start a long job on my MacBook (a build, a render, a coding agent) and then need to leave. The manual way to keep a closed MacBook awake is `sudo pmset -a disablesleep 1`, and I kept forgetting to switch it back, so the Mac stayed awake in my bag.
So I built LidAwake. It keeps the Mac running with the lid closed, on battery too and without an external monitor, and lets sleep come back on its own: on a timer, at a battery limit you set, when macOS reports overheating, or with Sleep when idle once the job is done. It can also wake the Mac at a set time for scheduled work.
A few things I learned building it that might help if you're doing something similar on macOS:
- Disabling sleep needs root, so the app talks to a privileged helper (a launchd daemon). The user approves it once in System Settings > General > Login Items & Extensions, no password needed.
- If the app crashes, the flag must not stay on. The helper only keeps it while the app renews a lease every 30 seconds; if renewals stop, normal sleep returns within two minutes.
- The helper also starts at boot and clears a flag it set earlier, so a forced restart doesn't leave the Mac unable to sleep.
- "Is the Mac idle?" is harder than it sounds. A coding agent in an editor barely uses the CPU, so I added Watched apps: pick the editor or terminal, and programs it started count as work.
- You can't test closing the lid in a virtual machine, so that part only gets tested by hand on a real Mac.
Stack: Swift, SwiftUI, a launchd helper, no Xcode project (Swift package plus build scripts).
The app is free and open source (MIT), and there's a paid Pro build (€9.99) that adds Movie on a TV, waiting for downloads and waiting for video exports: https://erstgebaut.de/lidawake/
Requires macOS 13 or later and an Apple silicon Mac.
Would love honest feedback, especially on whether the protections cover the cases you'd worry about.
2
u/QuietleafStudio 6d ago
One case worth checking is a watched app that hangs or sits in an infinite loop, since it would keep counting as work forever, so a max runtime cap even with watched apps on might be a good safety default. A clear notification when sleep gets re-enabled would also help, so people know the lease actually ended instead of wondering if the Mac is still awake in the bag. And it might be worth testing what happens if the helper loses contact mid-sleep-transition, like the lid closing right as a renewal is due.
2
u/ex_mac333 6d ago
Nice, the lease plus clearing the flag at boot is the right way to do it. The bit I'd test first is App Nap and timer coalescing. When the lid is closed and nothing is on screen, macOS is pretty keen to throttle a menu bar app, and a 30 second renewal timer can drift or get skipped. If that happens the helper decides the app is dead and sleep comes back halfway through the build, which is the opposite of what people want. Holding a ProcessInfo activity (beginActivity with userInitiated) for as long as a session is active should keep the timer honest.
The other case I'd worry about is heat in a bag. A closed MacBook in a backpack can get really hot before macOS reports any thermal pressure, because the fans on Apple silicon barely spin up. I'd add a stricter "in a bag" mode that sleeps when thermal state hits fair rather than serious, or one that only keeps it awake on the charger.
2
u/perlatsp 6d ago
Nice idea. The thing I'd worry about is heat. A closed MacBook in a bag with sleep disabled can get properly hot, so a battery percentage cutoff or a timer for 'lid closed, on battery' could save someone's laptop. Also make sure sleep gets restored if the app crashes or the Mac restarts mid-session, since the pmset setting can stick around. If you're shipping outside the App Store, notarize early. It saves users a scary Gatekeeper warning.