I just wrote my first application in Swift 3 for OS X. How can I configure this app to launch when the user logs in?
This worked for me, but there are some restrictions. First, the application must reside in the Applications folder. Second, I've seen it recommended that a "helper" app be included in the target app bundle to perform the actual startup… but I must admit that I don't know why that is necessary.
if SMLoginItemSetEnabled(appBundleIdentifier as CFString, true) {
log.info("Successfully added login item.")
} else {
log.warning("Failed to add login item.")
}
The last argument tells the system whether to add (true) or remove (false) the application from startup. Google SMLoginItemSetEnabled
for more details. Otherwise I am wrestling with this myself and I'd welcome someone to expand on this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With