Access to Safari bookmarks from another applicatio

2019-03-12 20:44发布

问题:

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.

回答1:

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).