Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FB5418390: Add ability to check the status of SMLoginItemSetEnabled ("Launch at login" functionality) #16

Closed
sindresorhus opened this issue Aug 11, 2019 · 2 comments

Comments

@sindresorhus
Copy link
Member

sindresorhus commented Aug 11, 2019

  • Date: 2018-10-11
  • Resolution: Fixed
  • Area: AppKit
  • OS: macOS 10.14
  • Type: Suggestion

Description

Sandboxed apps must use the SMLoginItemSetEnabled method to enable/disable enable an app to be launched at login (through a helper app). Usually, you would have a checkbox in the app's preferences to toggle it, like [ ] Launch at login. The problem is that there is no way to know whether the helper app is set to be launched at login or not. So you can't correctly show the status in the checkbox. The SMLoginItemSetEnabled method only lets us set the status, but not check it. We could persist the status to UserDefaults, but then it could easily get out of sync (Has happened to my app before). A common workaround is to use SMCopyAllJobDictionaries to check the status 0, but that API has been deprecated since macOS 10.10 with no replacement...

Expected Results:
I expected there to be a way to check the current status of SMLoginItemSetEnabled. There could be a method called SMLoginItemIsEnabled that would accept a bundle identifier and return a bool of whether it's enabled or not.

Actual Results:
Have to use UserDefaults which can be buggy or a deprecated API (SMCopyAllJobDictionaries).

Notes:
Relevant GitHub issue: sindresorhus/LaunchAtLogin-Legacy#12

@sindresorhus
Copy link
Member Author

I just noticed that the SMCopyAllJobDictionaries header says:

For the specific use of testing the state of a login item that may have been enabled with SMLoginItemSetEnabled() in order to show that state to the user, this function remains the recommended API. A replacement API for this specific use will be provided before this function is removed.

I'm not sure if this was always there or if it's new.

@sindresorhus
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant