In my Mac app, I've been using SMCopyAllJobDictionaries()
to check whether the app will be launched automatically at login. Basically, I get an array of all the login items and check whether my Bundle ID is in the array.
This function call works until Mavericks, but is deprecated in Yosemite. According to Apple,
This routine is deprecated and will be removed in a future release. There will be no provided replacement.
However, how can I do the same job in Yosemite? I do have to check whether my app is in the list of login items, in order to show a check box properly. I couldn't find relevant documentation from Apple.
On your Mac, choose Apple menu > System Preferences, then click Users & Groups . Click your account name below Current User, then click Login Items at the top of the window. Make a list of the login items—you'll need to remember them later.
Open Finder on your Mac. From the menu bar, select Go > Go to Folder… Find the LaunchAgents and LaunchDaemons folders containing your Startup Items.
Right-click on the app and hover over Options in the menu. Apps that are set to open automatically will have a check mark next to Open at Login. Click that option to uncheck it and disable it from opening.
Built on the only decentralised authentication infrastructure. Your OpenLogin account is a cryptographic key that acts as a proxy to traditional SSOs. Accounts are secured across user devices and authentication methods - there is no central server, no data honey pot. Learn more.
After some research it appears that there isn't an easy answer to this, period. After testing multiple apps including F.lux and BetterSnapTool, I've been able to easily desynch their user interfaces from the system preferences. If I enable "launch on start up" in any of these apps, then remove them from the system preferences log in items section, then relaunch them, their interfaces still think they are set to launch on start up. Interacting with their checkboxes does nothing, as the apps try to remove themselves from the list they no longer belong to and a second click is required to do anything.
To me this signifies that they keep their own internal state as a BOOL and save it between launches and that there simply isn't a way to get the list to synch with as of Yosemite. If someone knows otherwise I'll give them the bounty.
As of WWDC 2017, Apple engineers have stated that this is still the preferred API to use.
However, using this API will cause your build to fail. Don't turn off all deprecated function warnings. Instead, to enable your app to compile, wrap SMCopyAllJobDictionaries
with the following:
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" CFArrayRef cfJobDicts = SMCopyAllJobDictionaries( kSMDomainUserLaunchd ); #pragma clang diagnostic pop
If this issue is important to your app and you'd like Apple to provide a clean solution, please file a radar; this helps Apple engineers determine priorities of work items.
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