Show HN: LidAwake – Keep your Mac awake with the lid closed (200 lines of Swift)

deezedd1 pts0 comments

GitHub - deezeddd/LidAwake-Mac · GitHub

/" data-turbo-transient="true" />

Skip to content

Type / to search

Sign in<br>Sign upAppearance settings

You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

deezeddd

LidAwake-Mac

Public

Notifications<br>You must be signed in to change notification settings

Fork

Star

main

BranchesTags

Go to file

CodeOpen more actions menu

Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit

History<br>6 Commits<br>6 Commits

assets

assets

.gitignore

.gitignore

Info.plist

Info.plist

LICENSE

LICENSE

README.md

README.md

build.sh

build.sh

install.sh

install.sh

main.swift

main.swift

setup-permissions.sh

setup-permissions.sh

View all files

Repository files navigation

☕ LidAwake

Keep your Mac awake with the lid closed. One click from the menu bar.

A native macOS menu bar utility with no Dock icon, no Electron, no background daemons,<br>and an entire codebase you can read in one sitting.

Why LidAwake?

macOS only keeps running with the lid closed when an external display is attached (clamshell mode). If you want to close the lid while a build finishes, a server runs, or music plays, your options are third-party apps or remembering pmset incantations. LidAwake wraps the official Apple power-management flag in a one-click menu bar toggle, and adds one thing nothing else does: it remembers your display brightness across every lid close and reopen.

Features

☕ One-click toggle : a coffee cup in the menu bar. Outline cup means normal sleep, filled cup means the Mac keeps running with the lid closed.

🔆 Brightness memory : on lid close, your current brightness is saved and the panel is set to zero. On reopen, it is restored to the exact level you had. Works around regular display sleep too.

🔁 Always truthful : the icon reflects the real system state every time the menu opens, even if you changed the setting from the terminal.

🚀 Start at Login : one menu item, implemented with Apple's SMAppService.

🪶 Native and tiny : AppKit, SF Symbols, standard dialogs. Adapts to light and dark mode. A few MB of RAM.

📜 Audit trail : every lid and brightness event is logged to ~/Library/Logs/LidAwake.log.

Installation

Requirements

macOS 13 Ventura or newer (developed and tested on macOS 26)

Xcode or the Xcode Command Line Tools (xcode-select --install)

Quick install (one line)

curl -fsSL https://raw.githubusercontent.com/deezeddd/LidAwake-Mac/main/install.sh | bash

This downloads the source, builds it locally in a few seconds, and installs ~/Applications/LidAwake.app. Because the app is compiled on your own machine, there is no unsigned binary for Gatekeeper to complain about, and you can read every line of what you just ran, including the installer.

Or build from a clone

git clone https://github.com/deezeddd/LidAwake-Mac.git<br>cd LidAwake-Mac<br>./build.sh # compiles and installs ~/Applications/LidAwake.app<br>./setup-permissions.sh # one-time rule so the toggle needs no password<br>open ~/Applications/LidAwake.app

Note<br>setup-permissions.sh installs a sudoers rule scoped to exactly two commands, pmset -a disablesleep 1 and pmset -a disablesleep 0, for your user only. It is validated with visudo before being installed. If you skip this step, the app shows a dialog with the command whenever you try to toggle.

Usage

Menu item<br>What it does

Keep Awake When Lid Is Closed<br>Toggles lid-awake mode. Checkmark and filled cup when active.

Start at Login<br>Registers or unregisters the app as a login item.

Quit Lid Awake<br>Quits the app. The sleep setting stays however you left it.

Warning<br>While the toggle is ON, the Mac will not sleep for any reason, including on battery inside a bag. Toggle it off before you pack up. The filled cup is your reminder. A lid-closed laptop also dissipates heat worse, so AC power is best.

How it works

Piece<br>Mechanism

Sleep toggle<br>Apple's supported pmset disablesleep flag, flipped via sudo -n. No kernel extensions, no SIP changes, no hacks.

Lid detection<br>Closing the lid does not fire a display-sleep notification; macOS disconnects the built-in display entirely. LidAwake polls the AppleClamshellState property of IOPMrootDomain every 2 seconds to catch lid transitions reliably.

Brightness<br>The private DisplayServices framework (DisplayServicesGetBrightness / SetBrightness), the same API used by MonitorControl. The saved level lives in UserDefaults with a no-overwrite guard, so a crash between close and open never loses your original brightness.

FAQ

Is this dangerous?<br>No. disablesleep is an official power-management flag and is fully reversed by toggling off (or sudo pmset -a disablesleep 0). The app itself runs unprivileged. The only real caution is behavioral: see the warning above about bags and batteries.

Why does it need a...

lidawake menu toggle closed brightness sleep

Related Articles