Add “Launch at Login” functionality to your macOS app in seconds
Warning
The Mac App Store guidelines require “launch at login” functionality to be enabled in response to a user action. Your app will be rejected if you set the state to true by default
- macOS 13+
- For legacy versions check out the old
LaunchAtLoginpackage
Add https://github.com/TopScrech/LaunchAtLogin in the “Swift Package Manager” tab in Xcode.
Put the toggle in your Settings scene. That's it.
import SwiftUI
import LaunchAtLogin
@main
struct MyApp: App {
var body: some Scene {
Settings {
Form {
LaunchAtLogin.Toggle()
}
}
}
}The LaunchAtLogin.Toggle view works similarly to the built-in Toggle except that is has a predefined binding and label
The default label is "Launch at login", but it can be overridden:
import SwiftUI
import LaunchAtLogin
struct SettingsScreen: View {
var body: some View {
LaunchAtLogin.Toggle("Launch at login 🦄")
// Or
LaunchAtLogin.Toggle {
Text("Launch at login 🦄")
}
}
}You can also access the state directly:
import LaunchAtLogin
print(LaunchAtLogin.isEnabled)
// false
LaunchAtLogin.isEnabled = true
print(LaunchAtLogin.isEnabled)
// true- Defaults - Swifty and modern UserDefaults
- KeyboardShortcuts - Add user-customizable global keyboard shortcuts to your macOS app
- DockProgress - Show progress in your app's Dock icon
- More…