Skip to content

fix: restore user environment for SMAppService - #56

Open
oomathias wants to merge 1 commit into
jackielii:mainfrom
oomathias:fix/smappservice-user-environment
Open

oomathias wants to merge 1 commit into
jackielii:mainfrom
oomathias:fix/smappservice-user-environment

Conversation

@oomathias

Copy link
Copy Markdown

Summary

  • Restore HOME and USER when macOS 27 SMAppService omits them.
  • Preserve environment values supplied by the caller.
  • Run the repair before config discovery, daemon logging, and PID-file handling.
  • DISCLAIMER: This was mostly done by codex investigating the crash loop I had every restart

Problem

On macOS 27.0, the SMAppService LaunchAgent starts as the logged-in user but does not receive HOME or USER. Running under the user's UID does not create the environment of a login shell.

Without HOME, skhd cannot find ~/.config/skhd/skhdrc and falls back to a relative skhdrc path. Startup then fails with FileNotFound.

The missing variables also break the daemon log path and PID-file name. The daemon uses /tmp/skhd_unknown.pid, while skhd --status looks for the current user's PID file.

ensureUserEnvironment reads the current account with getpwuid(getuid()). It sets only the missing variables, so terminal launches and explicit environment overrides keep their existing values.

Verification

  • zig build test
  • git diff --check
  • zig build sign-app -Doptimize=ReleaseFast
  • Tested on macOS 27.0 build 26A5421a.
  • Started the packaged LaunchAgent through SMAppService with the repository's default skhd-cert identity.
  • Confirmed that skhd --status reports the daemon running, the event tap active, and Input Monitoring granted.

@oomathias
oomathias marked this pull request as ready for review August 26, 2026 21:18
@jackielii

Copy link
Copy Markdown
Owner

Thanks for the PR. Let's revisit this when macOS27 goes out of beta. Maybe we don't need this fix by then.

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.

2 participants