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?
Swift 3 OS X app launch on startup
Possible duplicate of Make Swift Cocoa app launch on startup on OS X 10.11 –
Nevski
No, this isn't my post. –
Self
Clarified that auto-launch is the goal. –
Miyamoto
@Self agreed that isn't your post, but it seems to answer your question. –
Miyamoto
@Miyamoto I have already see this post but the solution use old version of Swift and doesn't work with Swift 3 I have alrealdy try :( –
Self
@Self Actually, the solution there doesn't show any code; it's just links. –
Miyamoto
What do you mean ? –
Self
You can use this library github.com/sindresorhus/LaunchAtLogin –
Sorrento
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.
Applications are not able to use their own bundle identifier in this way, so that is why many choose to use a second target. Reference: theswiftdev.com/2017/10/27/how-to-launch-a-macos-app-at-login –
Faun
© 2022 - 2024 — McMap. All rights reserved.