Skip to content

Add launch-at-login and auto-enable protection options #1

Open

Description

@122yjs

Feature request

Add optional startup automation settings for unattended Macs running long tasks:

  1. Launch KeepAgentAwake at login
  2. Enable Never Sleep automatically when the app launches

Both options should default to off so the current behavior remains unchanged.

Motivation

KeepAgentAwake is very useful for long-running work such as builds, downloads, demos, and AI agents. For unattended or server-like Macs, however, there is one missing operational piece:

  • after a reboot or login, the app does not automatically start unless the user configures it manually
  • even if the app is started manually or through macOS Login Items, Never Sleep still needs to be toggled on again

This makes it less reliable for machines that are expected to keep background agents running after a restart.

Proposed solution

Add two independent settings in the app UI:

[ ] Launch KeepAgentAwake at login
[ ] Enable Never Sleep when KeepAgentAwake launches

Suggested behavior:

Launch at login Enable on launch Result
off off current behavior
on off app appears in the menu bar after login, but protection remains off
on on app starts after login and automatically enables Never Sleep
off on protection starts automatically only when the user manually opens the app

For macOS 13+, the login item setting could use SMAppService.mainApp from the ServiceManagement framework instead of manually installing a LaunchAgent plist.

Pseudo-code direction:

import ServiceManagement

func setLaunchAtLogin(_ enabled: Bool) throws {
    if enabled {
        try SMAppService.mainApp.register()
    } else {
        try SMAppService.mainApp.unregister()
    }
}

var launchAtLoginEnabled: Bool {
    SMAppService.mainApp.status == .enabled
}

The "Enable Never Sleep on Launch" option can be stored in UserDefaults, similar to the existing app preferences, and then checked near the end of applicationDidFinishLaunching:

if enableProtectionOnLaunch {
    DispatchQueue.main.async {
        self.startProtection()
    }
}

Safety notes

The automatic protection setting should probably be separate from the login item setting because some users may want the app to appear in the menu bar after login without immediately changing power behavior.

One edge case to consider: if "keep awake on lid close" is enabled, auto-starting protection may trigger pmset -a disablesleep 1, which can require administrator approval. It may be worth either documenting that clearly or avoiding an unexpected admin prompt during automatic launch.

Alternatives considered

  • Users can manually add the app to macOS Login Items, but that only launches the app; it does not automatically enable Never Sleep.
  • A user-level LaunchAgent could start the app, but SMAppService.mainApp seems like a better fit for macOS 13+ and should integrate better with System Settings → Login Items.

Expected benefit

This would make KeepAgentAwake more reliable for unattended Macs running long-lived agents, CI/build tasks, downloads, or home-server-style workloads while preserving the current default behavior for normal desktop users.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions