Search code examples
macosnsfilemanagerpkgbuildproductbuild

pkgbuild and moved application


I create an application installer with pkgbuild and productbuild tools on OS X. The package I create installs my application to /Application folder. Now, if I move this application to another location using NSFileManager(using another my app), my package will reinstall it to the new location but the /Application where it is intended to be installed.

This looks like some file path caching, can I somehow "flush the cash" so my pkg will install app to the right location?

I noticed this on Mavericks and El Capitan. I believe this is true for Yosemite too.


Solution

  • if I move this application to another location

    OS X doesn't like multiple, identical copies of the same application. The problem is due to the registration of applications when they're seen by Launch Services.

    When an application is copied into /Applications, or run for the first time, the application details are registered with Launch Services. When a user runs the application by double-clicking on its bundle, Launch Services looks at the registered applications and decides what actually gets run.

    The OS X Installer works in tandem with Launch Services, so when a bundle is due to be copied from a package, it first checks to see if the same application has been registered and exists; if the application has, then the copy won't occur. This can be viewed in the Install logs in /var/log/install.log

    Having multiple copies of the same application can get confusing and I recommend you don't do this. If you want to put aside a bundle and re-install, move it to the Trash, which will remove its registration from Launch Services.