<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aermin Huang</title>
    <description>The latest articles on DEV Community by Aermin Huang (@aermin_huang_f944a5471b8a).</description>
    <link>https://dev.to/aermin_huang_f944a5471b8a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4071530%2Fc258128c-215d-44b8-a9d5-1160f943d022.png</url>
      <title>DEV Community: Aermin Huang</title>
      <link>https://dev.to/aermin_huang_f944a5471b8a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aermin_huang_f944a5471b8a"/>
    <language>en</language>
    <item>
      <title>Building LidGuard: a safer way to keep your Mac running with the lid closed</title>
      <dc:creator>Aermin Huang</dc:creator>
      <pubDate>Mon, 10 Aug 2026 16:14:34 +0000</pubDate>
      <link>https://dev.to/aermin_huang_f944a5471b8a/building-lidguard-a-safer-way-to-keep-your-mac-running-with-the-lid-closed-414m</link>
      <guid>https://dev.to/aermin_huang_f944a5471b8a/building-lidguard-a-safer-way-to-keep-your-mac-running-with-the-lid-closed-414m</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftc00ixs2azsx70jmsw4a.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftc00ixs2azsx70jmsw4a.jpg" alt="A developer carrying a partially open laptop on the street so a coding task can keep running" width="800" height="1000"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Ever carried your Mac like this just to keep a coding task alive?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Sometimes I need to leave with my MacBook closed while a long Codex task, build, download, or phone-based remote-control session is still running. By default, closing the lid puts macOS to sleep and interrupts all of that work.&lt;/p&gt;

&lt;p&gt;I built &lt;strong&gt;LidGuard&lt;/strong&gt;, an MIT-licensed SwiftUI menu bar app, to make this a deliberate and reversible choice instead of a hidden global setting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two explicit modes
&lt;/h2&gt;

&lt;p&gt;LidGuard keeps the product model intentionally small:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keep Running&lt;/strong&gt; lets the Mac continue working after the lid closes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Normal Sleep&lt;/strong&gt; immediately returns lid-close behavior to macOS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Keep Running&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fua5o2fwjjr09xwro3fit.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fua5o2fwjjr09xwro3fit.png" alt="LidGuard Keep Running mode in the macOS menu bar" width="800" height="911"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Normal Sleep&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flwe7ipmy0rx1lzbnp5h5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flwe7ipmy0rx1lzbnp5h5.png" alt="LidGuard Normal Sleep mode in the macOS menu bar" width="800" height="879"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I deliberately did &lt;strong&gt;not&lt;/strong&gt; install Codex or other agent hooks. An agent starting or finishing should not silently change a machine-wide power setting. The user starts a LidGuard session explicitly and can see its current state in the menu bar.&lt;/p&gt;

&lt;p&gt;That also makes the app useful beyond AI agents: remote access from a phone, long builds, downloads, data processing, and other background work all fit the same model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recovery safeguards
&lt;/h2&gt;

&lt;p&gt;The difficult part was not keeping the Mac awake. It was making sure the setting did not remain enabled accidentally.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fospioxxctzdlhuowb9re.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fospioxxctzdlhuowb9re.png" alt="LidGuard timer, low-battery threshold, and thermal safeguard controls" width="800" height="1399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LidGuard provides three safeguard profiles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Strict&lt;/strong&gt; requires a deadline and restores normal sleep at 30% battery or serious thermal pressure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Balanced&lt;/strong&gt; supports timed or unlimited sessions and an adjustable 10%-50% battery threshold.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manual&lt;/strong&gt; gives more control, but critical thermal pressure always restores normal sleep.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Timed sessions can run for up to seven days, and the app warns five minutes before a deadline. Battery protection applies only while discharging, so connecting power does not unexpectedly end a session.&lt;/p&gt;

&lt;h2&gt;
  
  
  A narrow implementation
&lt;/h2&gt;

&lt;p&gt;The menu bar UI is unprivileged. A limited root helper performs only structured start, stop, update, and status operations. It does not accept arbitrary shell commands or file paths.&lt;/p&gt;

&lt;p&gt;Internally, LidGuard changes only the system's &lt;code&gt;SleepDisabled&lt;/code&gt; state and verifies the result after every change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;pmset &lt;span class="nt"&gt;-a&lt;/span&gt; disablesleep 1  &lt;span class="c"&gt;# Keep running&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;pmset &lt;span class="nt"&gt;-a&lt;/span&gt; disablesleep 0  &lt;span class="c"&gt;# Restore normal sleep&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It does not create a virtual display, capture the screen, change &lt;code&gt;sleep&lt;/code&gt; or &lt;code&gt;displaysleep&lt;/code&gt;, or add an extra &lt;code&gt;caffeinate&lt;/code&gt; assertion. If another tool changes the setting, LidGuard does not continually fight it.&lt;/p&gt;

&lt;p&gt;The helper persists the session deadline and safeguards, so protection continues even if the menu bar app exits or the helper restarts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try the preview
&lt;/h2&gt;

&lt;p&gt;The current preview supports &lt;strong&gt;Apple Silicon Macs running macOS 13 or later&lt;/strong&gt;. It includes the menu bar app, privileged helper, and a &lt;code&gt;lidguard&lt;/code&gt; CLI.&lt;/p&gt;

&lt;p&gt;Because I am distributing this without a paid Developer ID certificate, the build is ad-hoc signed. The README documents the one-time &lt;strong&gt;System Settings → Privacy &amp;amp; Security → Open Anyway&lt;/strong&gt; step. After the helper is installed once, normal mode switching does not require another administrator password.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GitHub: &lt;a href="https://github.com/aermin/LidGuard" rel="noopener noreferrer"&gt;https://github.com/aermin/LidGuard&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Download: &lt;a href="https://github.com/aermin/LidGuard/releases" rel="noopener noreferrer"&gt;https://github.com/aermin/LidGuard/releases&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;License: MIT&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I would especially appreciate feedback on the safety defaults, remote-control compatibility, and the explicit-session model. If LidGuard is useful to you, please consider giving the repository a ⭐️ on GitHub so more people can discover it.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>swift</category>
      <category>opensource</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
