Can someone smarter than me take a look at this script to automate shutdown after lid close for X amount of minutes?

Help

Scenario: Lid close "sleep" for me is like 1-2% per hour. There are also times I don't use my laptop at all for that day, so repeatedly draining down to 0% is gonna degrade this battery like crazy. Sure I could SHUT DOWN, and I often do, but there's times I just forget.

I asked chatgpt to help write me a script that does the following:

  • after lid close, a timer starts
  • if lid remains closed for (1 hour for example), then a full shut down is triggered (yea i dont care about unsaved work)
  • if lid opens before the 1 hour, then shutdown is cancelled

What I found was that Asahi doesn’t expose a standard RTC wake path, so the normal Linux solution of:

  • suspend, wake itself later, shut down

doesn’t currently work the same way it would on ThinkPads or normal x86 laptops.

The issue isn’t that the Mac lacks a clock/timer — it’s that Linux on Apple Silicon doesn’t currently expose a generic wake-capable RTC interface that works with rtcwake or /sys/class/rtc/.../wakealarm.

So the final workaround I landed on was:

  • disable lid suspend entirely
  • when lid closes, start polling UPower lid state every 2 seconds
  • if it stays closed for 5 minutes, do systemctl poweroff --no-wall
  • reopening the lid before then resets the countdown

So it’s basically:

  • closed lid for 5 minutes → auto poweroff
  • instead of true delayed shutdown-from-suspend.

This is not a suspend replacement, but it solves the real-world issue of:

  • close lid → toss in bag → forget about it → battery isn’t dead tomorrow

The 5-minute grace period gives enough time for accidental closes, quick moves between rooms, etc., while still preventing the overnight drain problem.

Heres the script and "guide" I had it print out if you care to take a look at it: https://sharetext.io/u6vleo2i

Wondering if this is a good idea, or bad idea and im overlooking something, or even better if someone has a better solution.

Posted Apr 6, 2026, 1:11 AM UTC

125
Loading comments…