Search code examples
cocoamacosiphoto

NSOpenPanel limit selection to iPhoto library


When using NSOpenPanel to open files, I am trying to let the user only select iPhoto libraries. An Aperture library, for example, has the extension .aplibrary. An iPhoto library, however, seems to have no extension.

For your information, the Aperture and iPhoto libraries are bundles to be completely correct. The Aperture bundles have an .aplibrary extension while the iPhoto bundles seem to have no extension.

How can I let the user only select iPhoto bundles? Due to the lack of an extension I cannot use "setAllowedFileTypes". iPhoto, however, does seem to be able to make the distinction, but I don't see how that's done in this case.


Solution

  • NSOpenPanel has a delegate, which should implement NSOpenSavePanelDelegate. One of the methods on that is -panel:shouldEnableURL: - if you implement that method, you can detect whether to let someone open a location based on whatever logic you want.