14

I was wondering how we can access Safari bookmarks from another Cocoa application on Mac OS X, in a way that is safe and secure for the future.

As you may know, two mechanisms were common to retreive Safari bookmarks:

  • either read Safari's Bookmarks.plist file
  • or use the SyncServices API.

However, the first is forbidden by sandboxing (mandatory for a distribution through the App Store), and the second has been deprecated since Mac OS X 10.7 Lion.

I believe that Apple deprecated SyncServices in favour of iCloud synching, but I can't find any iCloud API that allow access to the bookmarks (1).

Any hint on where to look? Native Cocoa is preferred, but any non-deprecated, sandboxing-compatible solution is welcome.

Thanks.

(1) and, honestly, going through the internet (and thus requiring an internet connexion) to retrieve on a machine something on the same machine seems... awkward — but well, if it was the way to go at least that would be a possibility.

KPM
  • 10,558
  • 3
  • 45
  • 66

1 Answers1

4

You can read out the bookmarks plist file even when running in a sandbox if you expressly ask the user for consent: Present an open panel pointing to the plist directory and store the security-scoped bookmark you receive from it. I did this and my app wasn't rejected for this (but for other things).

Tim
  • 1,659
  • 1
  • 21
  • 33
  • Oh, that seems cool. So NSSearchPathForDirectoriesInDomains still works with sandboxing then? – KPM Aug 16 '12 at 00:20
  • It will run, but return different paths if called from a sandboxed app. You'll have to manually separate the path components and put them together again to create the correct path if you want to access files outside the sandbox. – Tim Aug 16 '12 at 05:46
  • Hmm, so it's still a kind of a hack that might be broken overnight by Apple. Better use deprecated APIs then, at least we get prior notice... Thanks for the input anyway. – KPM Aug 16 '12 at 15:09