5

I'm writing a command-line daemon to read images from iPhoto.

I can init and load an MLMediaLibrary fine from a full-blown Cocoa application, created using the Xcode project creation tools. However, when I try and do the same from a command-line tool (also created in Xcode), the following error appears in Xcode console window:

MLMediaLibrary error obtaining remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "Couldn’t communicate with a helper application."

How can I access MLMediaLibrary from a command-line tool?

damian
  • 3,604
  • 1
  • 27
  • 46

2 Answers2

8

In order to access MLMediaLibrary your application has to be sandboxed and codesigned.

Update

It seems like you also have to add some permanent read-only access entitlements to your .entitlements file.

If you want to access Photos, iPhoto or Aperture libraries:

<key>com.apple.security.assets.pictures.read-only</key>
<true/>

If you want to access iMovie and FinalCut:

<key>com.apple.security.assets.movies.read-only</key>
<true/>

If you want to access iTunes or Logic:

<key>com.apple.security.assets.music.read-only</key>
<true/>

You can read about my poor experience with a MediaLibrary framework here: https://devforums.apple.com/message/1125821

  • Thank you, this looks very helpful! I'll accept once I've had a chance to check that it works for me. – damian Apr 16 '15 at 09:44
  • Is it possible to use MediaLibrary.framework without sandboxing my app, as I have to access some external storage devices (flash drive, etc.). See my question here: http://stackoverflow.com/questions/40901811/access-medialibrary-framework-without-sandboxing-on-mac – Hao Xi Dec 01 '16 at 08:50
-2

I don't think Konstantin's statement is correct: In order to access MLMediaLibrary your application has to be sandboxed and codesigned.

Per my test, I can use MediaLibrary.framework within my application and my application is not code signed, it doesn't have an entitlements file, so it is abviously not a sandboxed app.

Hao Xi
  • 351
  • 4
  • 12