Hello,
I have many apps that use LoginItem logic to enable the auto start.
I always used the function SMLoginItemSetEnabled
to enable or disable the launch of the LoginItem.
I am using macOS Ventura Beta for quite some time now and I noticed that whenever I launch one of my apps, a message appears. It says that my app added some functions. When I click on the message, the Login Items section of the System Preferences opens and my recently opened app is listed under "Allow in the Background".
I want to port my apps to the new logic but I am not quite sure how to do that. I don't want my apps to appear under the "Allow in the Background" section but rather in the "Open at Login" section.
I am using the following code to enable or disable the auto start under macOS 13.0+:
if autoLogin
{
try? SMAppService.mainApp.unregister()
}
else
{
try? SMAppService.mainApp.register()
}
This works very well. If I check my switch, the app appears under the "Open at Login" section. If I disable the switch, the app disappears from this list. Great, this is what I want. However...when I restart my Mac, the app is launched automatically. And now there is a new entry in the "Allow in the Background" section again.
What am I doing wrong? Should I register or unregister the LoginItem instead? This is not really what I want, it appears in the wrong section and I think this is confusing for users.
I read somewhere else that the user consent is stored, even when resetting with sfltool or something like that. Does the item appear in this section (and is launched automatically) because I launched the app earlier without my new logic?
Is this simply a bug?
has anyone a working example of how to properly support auto launching an application under macOS Ventura and earlier versions?
Regards, Sascha
I want to port my apps to the new logic but I am not quite sure how to do that. I don't want my apps to appear under the "Allow in the Background" section but rather in the "Open at Login" section.
These are very different things:
-
Open at Login shows a list of login items, per the legacy
kLSSharedFileListSessionLoginItems
API. These items are always launched at login, and are intended to be under the control of the user. -
Allow in the Background has different semantics. This is an allowlist. It doesn’t show what programs will be launched at login, it shows what programs are allowed to be launched at login [1].
You can see this with the SMLoginItemSetEnabled
API:
-
Enable your Service Management login item by calling
SMLoginItemSetEnabled
withtrue
. -
The item shows up in the Settings list.
-
Back in your app, disable your login item by calling
SMLoginItemSetEnabled
withfalse
. -
The item still shows up in the list.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Assuming we’re talking login items here. It also works for daemons but that’s not your focus.