TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED - Add launch at login to macOS app

Forums > macOS

Anyone recently added launch at login for a #macOS app? I've followed this… but it doesn't seem to work. I notarise my app, launch it and shut down my Mac but after starting again the app doesn't launch. Is this still the way to go?

My app is mainly build with SwiftUI and targets macOS Monterey and would greatly benefit from this feature.

According to the docs the SMLoginItemSetEnabled returns YES if the requested has taken effect. Below does return true for the state, so that should be working I guess. Wonder why it won't start.

.onChange(of: launchAtLogin) { newValue in
    let state = SMLoginItemSetEnabled(Constants.helperBundleID as CFString, newValue)
    print("Setting is enabled \(state)")


I've contacted the author of the article a little while back and he helped to figure it out, thought I'd mention it here too. The tutorial in the article works with the following adjustment:

In the applicationDidFinishLaunching function in the launcher target, the following two lines should be replaced:

guard let pathURL = URL(string: actualAppPath) else { return }
NSWorkspace.shared.openApplication(at: pathURL, configuration: NSWorkspace.OpenConfiguration())

With this:


The latter was deprecated in macOS 11.0 but somehow that solution does still work and the first one doesn't. Not sure it it's future proof for long, perhaps the new API's in macOS Ventura will offer a better solution.


I'll just leave it here

let appPath: String = {
  let path = Bundle.main.bundlePath as NSString
  var components = path.pathComponents
  return NSString.path(withComponents: components)
let appURL = URL(fileURLWithPath: appPath)
NSWorkspace.shared.openApplication(at: appURL,
configuration: NSWorkspace.OpenConfiguration(),
completionHandler: nil)



In case someone goes down this path... check out Sindre Sorhus LaunchAtLogin package.


Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.