Add ability to check the status of `SMLoginItemSetEnabled` ("Launch at login" functionality)

Originator:sindresorhus
Number:rdar://45183731 Date Originated:11-Oct-2018 11:29 AM
Status:Open (Duplicate of 19068037) Resolved:
Product:macOS + SDK Product Version:macOS 10.14
Classification:Enhancement Reproducible:Always
 
Summary:
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...

[0]: https://github.com/sindresorhus/LaunchAtLogin/blob/8cb7d331a02acb61250857e05cee20bcb8f0be98/LaunchAtLogin/LaunchAtLogin.swift

Steps to Reproduce:
 

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).

Version:
macOS 10.14

Notes:
Relevant GitHub issue: https://github.com/sindresorhus/LaunchAtLogin/issues/12

Comments

Apple Developer Relations

Engineering has determined that your bug report is a duplicate of another issue (19068037) and will be closed.

By sindresorhus at Oct. 19, 2018, 9:16 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!