LaunchAtLogin¶
The LaunchAtLogin service controls whether the app starts automatically when the user logs in. It uses SMAppService on macOS 13+ to register the app as a login item. Access it via app.launch_at_login.
if app.launch_at_login.enabled():
print("App will launch at login")
App Store Requirement
Per Mac App Store guidelines, Launch at Login should only be enabled in response to a direct user action (e.g., clicking a button or toggling a switch). Do not enable it silently or at startup.
Methods¶
enabled()¶
Whether the app is currently set to launch at login. It asks the system, so it blocks like any service call.
app.launch_at_login.enabled() -> bool
set(enabled)¶
Set the launch at login state. Call this only in response to a user action.
app.launch_at_login.set(enabled: bool) -> None
| Parameter | Type | Description |
|---|---|---|
enabled |
bool |
True to enable launch at login, False to disable |
Raises nib.ServiceError with the system's reason when the change is refused.
Examples¶
Toggle button¶
import nib
def main(app: nib.App):
app.title = "Settings"
app.icon = nib.SFSymbol("gear")
app.width = 300
app.height = 100
status = nib.Text("Checking...", foreground_color=nib.Color.SECONDARY)
def toggle():
current = app.launch_at_login.enabled()
app.launch_at_login.set(not current)
status.content = "Enabled" if not current else "Disabled"
def refresh():
enabled = app.launch_at_login.enabled()
status.content = "Enabled" if enabled else "Disabled"
app.on_appear = refresh
app.build(
nib.VStack(
controls=[
nib.HStack(
controls=[
nib.Text("Launch at Login"),
nib.Spacer(),
status,
],
),
nib.Button("Toggle", on_click=toggle, style=nib.ButtonStyle.BORDERED),
],
spacing=12,
padding=20,
)
)
nib.run(main)
Toggle with on_change callback¶
import nib
def main(app: nib.App):
app.title = "Preferences"
app.icon = nib.SFSymbol("gear")
app.width = 320
app.height = 80
def on_change(is_on):
app.launch_at_login.set(is_on)
toggle = nib.Toggle(
is_on=False,
label="Launch at Login",
on_change=on_change,
)
def refresh():
toggle.is_on = app.launch_at_login.enabled()
app.on_appear = refresh
app.build(
nib.VStack(
controls=[toggle],
padding=20,
)
)
nib.run(main)
Related¶
- Settings:
Settings