Skip to content

Add non-sandboxed macOS applications to user login items

License

Notifications You must be signed in to change notification settings

chrenn/LoginItemKit

Repository files navigation

LoginItemKit

Warning
With macOS 13, Apple introduced SMAppService and deprecated the Hide property.
Please use SMAppService or a wrapper like LaunchAtLogin-Modern for new projects.

A simple Swift package to add non-sandboxed macOS applications to user login items and to control their Hide property.

Screenshot

Overview

There are basically two ways to achieve Launch at Login functionality on macOS.

Let's compare LoginItemKit to the popular LaunchAtLogin package.

LaunchAtLogin LoginItemKit
Framework ServiceManagement LaunchServices
Deprecated Partly (10.10) Yes (10.11)
Sandbox support Yes  No
SwiftPM support Yes Yes
Needs helper app & build script Yes No
Shows up in system preferences No Yes

So feel free to use this package in all your non-sandboxed apps and let's hope that Apple does not remove the LaunchServices API from future versions of macOS.

The Hide checkbox

Checking Hide can cause problems for applications using high values for NSWindow.Level, e.g. the tooltip windows in Swish. Version 2 of LoginItemKit allows you to read and write this property.

Installation

SwiftPM

.package(url: "https://github.com/chrenn/LoginItemKit", from: "2.0.0")

API

LoginItemKit exposes a tertiary .launchState enum for granular control as well as a simple .launchAtLogin boolean.

launchState launchAtLogin { get, set }
Not in Login Items .none false, false
In Login Items & Hide checked .hide true, -
In Login Items & Hide unchecked .show true, true

Usage

import LoginItemKit

print(LoginItemKit.launchState, LoginItemKit.launchAtLogin)
// → .none, false

LoginItemKit.launchAtLogin = true

print(LoginItemKit.launchState, LoginItemKit.launchAtLogin)
// → .show, true

LoginItemKit.launchState = .hide

print(LoginItemKit.launchState, LoginItemKit.launchAtLogin)
// → .hide, true

Resources

Used by