SMLoginItemSetEnabled often launches an agent outside the app bundle

Number:rdar://22446403 Date Originated:2015-08-26
Status:Open Resolved:
Product:OS X Product Version:10.10
Classification:Serious Bug Reproducible:Sometimes
SMLoginItemSetEnabled is documented to:

> Enable a helper application located in the main application bundle's Contents/Library/LoginItems directory.

But it often doesn't work as expected.  It will often launch another copy of the agent elsewhere on the Mac, e.g. in the build or DerivedData folder, or in another copy of the app, etc.

This is a serious issue, particularly for developers, but potentially also for users who like to keep multiple versions (in case the want to revert). Launching an agent from an older version of the app leads to incorrect behavior.

I previously mentioned this issue on Stack Overflow:

Steps to Reproduce:
1. Have more than one copy of an app containing a login item.
2. Call SMLoginItemSetEnabled for the login item.

Expected Results:
The login item contained within the app bundle (at Contents/Library/LoginItems) will be launched.

Actual Results:
Sometimes a login item from another copy of the app (or in the build folder) will be launched.

All versions of 10.10, and earlier I believe.  Untested on 10.11, but probably there too.


Closed as duplicate of #17491721 (still open).

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at 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!