Skip to main content

Module login_item

Module login_item 

Source
Expand description

macOS: start at login through SMAppService, so the entry shows in System Settings -> General -> Login Items & Extensions where people look for it, and respects the approval they give there (docs/specs/SPEC_START_WITH_OS_2026_09_25.md §3.7, phase 4).

§What is registered, and why not SMAppService.mainApp

A bundle that ships Contents/Library/LaunchAgents/<label>.plist registers that agent (SMAppService.agent(plistName:)). The plist’s job is the launcher itself with --login-start: a shim that, at login, opens the app through LaunchServices (open <app> --args --background) unless it already runs, then exits.

  • mainApp cannot carry --background, which is what makes a login start a tray start with no window.
  • An agent whose job is AgentMux dies when the entry is switched off: unregistering boots the job out and launchd stops its process (checked on macOS 26.5, 2026-11-20). With the shim, the running app is a LaunchServices child, not the job, so Settings can switch the entry off from inside the app that login started.
  • A process started by launchd rather than LaunchServices is refused by UNUserNotificationCenter (“notifications are not allowed”, with no prompt; checked on macOS 26.5). Going through open keeps the login-started app able to notify.
  • BundleProgram must be a signed Mach-O inside the bundle: a shell script fails launchd’s launch constraints.

The plist ships only in a bundle whose identifier is stable across versions (scripts/package-macos.sh); a bundle without it keeps writing the LaunchAgent plist of autostart/mod.rs, so nothing changes for dev, test or per-version builds. Registering an entry replaces that LaunchAgent plist (no double start, no orphan).

Modules§

platform 🔒

Enums§

Registration
SMAppService.Status.

Constants§

AGENT_PLIST_DIR
The folder inside an app bundle that holds a registrable agent plist.
LOGIN_START_FLAG
What the launcher is asked to do by the login job: start AgentMux through LaunchServices if it is not running.
OPEN_LOGIN_ITEMS_FLAG
--open-login-items: open System Settings at Login Items (the page where the person approves AgentMux).

Functions§

agent_plist_in
The file name of the agent plist a bundle ships, when it ships exactly one. More than one is a packaging mistake (which would the system start?), so it counts as none.
available
Whether start at login goes through SMAppService in this launcher.
bundle
The app bundle and agent plist name this launcher registers: set when this launcher runs from an app bundle that ships an agent plist and the system has SMAppService (macOS 13). None everywhere else.
bundled_agent_plist 🔒
The agent plist the bundle that holds app ships: its file name, if it ships exactly one.
login_start
What the login job does: nothing when this app already runs (a registration made while it is open, or a second login item), otherwise open it through LaunchServices in background mode and leave. Returns the exit code.
open_settings
Open System Settings at Login Items, where the person allows AgentMux (status RequiresApproval).
register
Register the agent. Re-registering one that is registered is not an error.
registration
The registration as the system has it. None when available is false or the system does not answer.
registration_from_raw
The raw SMAppService.Status (notRegistered 0, enabled 1, requiresApproval 2, notFound 3).
unregister
Remove the registration. Succeeds when there is none.