macosservice-management

SMLoginItemSetEnabled returns success but doesn’t add login item


I’m trying to add a login item to a macOS app. The app is set to agent in its plist so it has no dock icon, hides its main window in launch, and places an icon in the status bar to provide its UI.

To add the login item, I have:

The problem is that although I get feedback from the app that SMLoginItemSetEnabled was successful, the helper app does not run on login, or if it runs, it does not launch the base app.

I looked inside the base app bundle and the helper app is in there. I can run it manually, and it does launch the base app. I can even manually add it as a login item through System Preferences and it still launches the base app. So it would appear that even though SMLoginItemSetEnabled is returning true, it is not actually installing the login item. Or if it is, it’s not able to launch and run the base app from the login item even though it can if I do it manually.


Solution

  • The solution to this was to delete the DerivedData folder for both the base app and the helper app. It would seem that the login item was confused about which copy of the app to open, and was presumably trying to open one from DerivedData. Deleting these folders and leaving only the app in /Applications allowed the helper app to launch the base app from the login item.