Is there a way to update SMLoginItemBookmarks data on launchd overrides.plist

492 views Asked by At

I'm working on an OS X app that most users choose to "launch at login", the kind you'd find at the menu bar.

In order to launch it at login I'm using SMLoginItemSetEnabled to launch a LoginHelper app that will open the main app, as described in this tutorial.

The app is failing to start up at login for just a handful of our users.

I was unable to reproduce this or to track the cause but I found (on a user's machine) that:

Deleting /Root/_com.apple.SMLoginItemBookmarks/[myapp] and /Root/[myapp] on /var/db/launchd.db/com.apple.launchd.peruser.$UID/overrides.plist and then resetting the Launch at login on the app fixed the issue. Also, we diff'd the files and the Data on the bookmark had changed.

For reference, I found about the overrides.plist here.

Since the app has both a Mac App Store and a Direct download version, I'm suspecting multiple copies of the app setting themselves as Launch at login may be the reason for this to fail, maybe these "bookmarks" are trying to open another instance of the app, that may or may not be deleted.

Now the questions, provided that this app needs to remain sandboxed:

  • Is there a way of updating that Data on the overrides.plist bookmarks?
  • Is there any way of deleting one self's app from the overrides.plist to start clean?
  • Is this maybe a known issue?
  • Any other suggestions on why the bookmark seems to point nowhere or how to fix it will be appreciated.

Note: This is my first question on StackOverflow, please excuse me if I failed to follow some of the suggested etiquette.

1

There are 1 answers

2
Jacob Gorban On

I don't know a definitive solution to this, I wasn't even aware of the overrides.plist. It could be related to multiple copies. As far as I understand, adding login through SMLoginItemSetEnabled sets a metadata flag that this Bundle ID should be launched on start. Then Spotlight, on start, will go do a metadata search on the file system and see which Bundle IDs need to be launched. Then, I guess, it will initiate the launch using the bundle ID. In my own application, Trickster, which uses the same technique for launching, I see that if I enable launch-on-login through the app itself, it might pop-up this strange message which refers to a debug build. I'm not even sure why it says about the first time. Very strange.

Message when enabling launch on login

So, to have them launched, you have to make sure that the relevant bundles are in locations where Spotlight indexes (that the user hasn't disable Spotlight for these locations). Usually users don't disable Spotlight, especially for /Applications/ but I'm just saying.

What I usually suggest when support comes my way (and how I have it set up for me because I have multiple copies), is I to disable launch from within the app and instead add the correct one (from /Applications) manually in Login Items in System Preferences.