Skip to content

Make the lock action sleep displays immediately - #3

Open
LorenzGit wants to merge 1 commit into
artemsvit:mainfrom
LorenzGit:fix/lock-and-sleep-displays
Open

Make the lock action sleep displays immediately#3
LorenzGit wants to merge 1 commit into
artemsvit:mainfrom
LorenzGit:fix/lock-and-sleep-displays

Conversation

@LorenzGit

@LorenzGit LorenzGit commented Aug 30, 2026

Copy link
Copy Markdown

Problem

When Code Awake is active, Allow Lock & Sleep replaces the PreventUserIdleDisplaySleep assertion with PreventUserIdleSystemSleep. This permits display sleep while keeping the Mac awake, but it does not actively turn the displays off.

The displays therefore remain on until the normal macOS display-sleep timer expires. macOS may also hold its own com.apple.powermanagement.delayDisplayOff assertion for a grace period after locking.

The existing lock button did not close that gap. It ran:

  1. /usr/bin/open -a ScreenSaverEngine
  2. the legacy CGSession -suspend helper

Those commands lock or show the login screen, but neither requests display sleep. The CGSession executable is also absent on newer macOS versions. The result can be a locked Mac with the monitors still lit.

Change

The explicit lock action now runs these commands sequentially:

  1. Launch ScreenSaverEngine.
  2. Run CGSession -suspend when that legacy executable exists.
  3. Run /usr/bin/pmset displaysleepnow.

Missing executables and launch failures do not stop the remaining commands. This preserves compatibility with older macOS versions while ensuring the final display-sleep request still runs.

pmset displaysleepnow powers off the displays. It does not put the whole Mac to sleep. Code Awake continues holding PreventUserIdleSystemSleep, so the Mac remains awake for running tasks.

This PR also updates the tooltip, welcome text, and README to distinguish the two behaviors:

  • Allow Lock & Sleep passively follows the normal macOS display-sleep schedule.
  • The lock button locks the Mac and turns the displays off immediately.

The assertion policy behind the toggle is unchanged.

Verification

  • Added a regression test for the exact command order.
  • All 16 tests pass.
  • The unsigned Release build passes.
  • A sandboxed, ad-hoc-signed macOS test build passes code-signature verification.
  • git diff --check passes.

Related to #2.

@LorenzGit LorenzGit changed the title Fix lock action to sleep displays Make the lock action sleep displays immediately Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant