2

I'm trying to figure out how I can access the ~/Library/Messages folder in my macOS app (swift). Specifically, I'm trying to access the chat.db file.

If I do the following (without sandbox), I get an open error.

let url = try? FileManager.default.url(for: .libraryDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
url = url!.appendingPathComponent("Messages", isDirectory: true).appendingPathComponent("chat.db", isDirectory: false)

// Then open this file...

If I instead point the user to the folder using an Open Dialog, I get a forbidden sign on the folder icon.

What permission do I need to be able to access this file? I've tried Accessibility but that doesn't seem to be it (and also I didn't grant iTerm accessibility and I can still go to that folder). Any pointer is appreciated. Thanks!

(I only need access to this one single file. If there's a way to do it in sandbox, I'd love to go that route. If that's not possible, asking for whatever permission is fine.)

danqing
  • 3,348
  • 2
  • 27
  • 43
  • 1
    I can't even list the contents of `~/Library/Messages` from a terminal window even using `sudo ls` without getting "operation not permitted". This suggests strongly to me, you are not supposed to look inside it. You'll need to find another way, perhaps using some API, so what are you really trying to do? – JeremyP Jan 15 '19 at 15:03
  • I'm trying to access the iMessage chat database. Yes I understand that normally this is a system folder and shouldn't be accessed. However, there are legitimate reasons when an app wants to have the access, and macOS is more flexible than iOS. – danqing Jan 16 '19 at 01:27

1 Answers1

3

You need to allow "Full Disk Access" for the applications that need to access that path:

enter image description here

This is part of the privacy changes in macOS Mojave.

TheNextman
  • 12,428
  • 2
  • 36
  • 75
  • Is there a way to prompt the user to grant the access? – danqing Jan 16 '19 at 06:21
  • You can't make the system prompt, but you can show your own prompt. You can navigate the user to the right place in System Preferences using a URL scheme: https://stackoverflow.com/questions/24701362/os-x-system-preferences-url-scheme. But the user must manually add your app to the list. – TheNextman Jan 16 '19 at 06:54