3

I think this is a problem specific to Yosemite because I didn't have any issues in Mavericks (or Mountain Lion before that)...

I have an application that I wrote which registers a helper app to run at startup using SMLoginItemSetEnabled. I'm not having any problems here; this works fine.

SMLoginItemSetEnabled works by taking a bundle identifier (such as "com.MyCompany.MyApp"), finding the path for that bundle via Launch Services, and running it at startup.

The problem is that when I "archive" my project, the archive build output is automatically registered as the bundle's path in Launch Services. On Yosemite, even if I copy that bundle to /Applications and run it, Launch Services will still point to the build path. Because my app is sandboxed, OSX will refuse to run the helper during boot.

For example:

$ osascript -e 'tell application "Finder" to set targetAppPath to (application file id "com.MyCompany.MyApp") as string'
Macintosh HD:Users:myuser:Library:Developer:Xcode:Archives:2014-10-30:MyApp 10-30-14, 9.57 AM.xcarchive:Products:Applications:MyApp.app

$ osascript -e 'tell application "Finder" to set targetAppPath to (application file id "com.MyCompany.MyAppHelper") as string'
Macintosh HD:Users:myuser:Library:Developer:Xcode:Archives:2014-10-30:MyApp 10-30-14, 9.57 AM.xcarchive:Products:Applications:MyApp.app:Contents:Library:LoginItems:MyAppHelper.app

Despite the fact that I've copied the bundle to /Applications and I'm currently running it from that location, launch services is still pointing to the build path.

In Mavericks and Mountain Lion, I ran into a similar issue if the last time I ran the app was in debug mode via the "play" button in xcode because Launch Services would have the path pointing to the debug build directory. But as soon as I built the archive and copied it to /Applications and ran it from there, everything was fine. It seems Yosemite will only update the Launch Services database if the bundle's version has changed, and that doesn't happen simply by copying the bundle from one place to another.

Does anyone have any ideas? Is there a way to force Launch Services to update the path to the bundle, either in code or via the command line?

bmatcuk
  • 453
  • 3
  • 10
  • 2
    Looks like rebuilding the Launch Services database works: `/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user` - not sure if I'll need to do that every time I rebuild my app =( – bmatcuk Oct 30 '14 at 21:06
  • So much thanks for that, I've also faced such issue and this really helps, but I need to call that command each time, I archive my app to test it – Alexander Semenov Dec 10 '15 at 16:51
  • Ya, I don't think there's any way around that =( – bmatcuk Dec 11 '15 at 21:31

0 Answers0