113

I updated to macOS Catalina which requires the user through pop-ups to allow any app trying to access the file system for the first time.

No such pop-up is appearing for Emacs. Running the script shared here, https://gist.github.com/dive/f64c645a9086afce8e5dd2590071dbf9
does not seem to change anything. That is, Emacs and any shell running in it cannot access any file on the file system.

How can I restore the access?

My Emacs version is *GNU Emacs 26.1 (build 1, x86_64-apple-darwin14.5.0, NS appkit-1348.17 Version 10.10.5 (Build 14F2511))

UPDATE
Granting the Emacs app Full Disk Access in "General Settings -> Security & Privacy -> Privacy" does not solve the problem.

wsaleem
  • 1,233
  • 3
  • 10
  • 8
  • 1
    Go to "General Settings -> Security & Privacy -> Accessibility" and add there Emacs, to allow it to control your computer. Then trying to open a file from Emacs will open a short dialog asking to confirm permission for that folder. The allowed folders will appear in Privacy -> File and Folders. Maybe it will be useful to upgrade to Emacs 26.3 – Ian Oct 08 '19 at 14:36
  • Thanks, Emacs was already allowed under Accessibility. I removed and re-added it. I also re-installed and thus upgraded to Emacs 26.3 in the meanwhile. All to no avail! – wsaleem Oct 08 '19 at 14:45
  • 1
    Is [this other post](https://emacs.stackexchange.com/questions/53248/finder-of-macos-catalina-cannot-open-a-file-with-emacs) dealing with the same or a different problem? I tried the selected solution of *this* problem—adding disk access to both Emacs *and* ruby—for *that solution and it didn't work, and I'm not sure if that's because the answer here isn't correct or because it's a different problem. – HaPsantran Nov 25 '19 at 16:11
  • The solution here solved the problem in this thread for me. I don't know about the other problem. – wsaleem Nov 25 '19 at 16:28
  • The accepted answer doesn't work, as noted. I got it to work by reading [this thread on github](https://gist.github.com/dive/f64c645a9086afce8e5dd2590071dbf9) I ran the script suggested in the thread, but it didn't help, but then I did `M-x ns-open-file-using-panel` and opened `~/Download` opened a file. And then it worked. So now it works fine for me at least. But I had to re-do it for `~/Documents` etc. – larsr Jan 19 '20 at 20:30
  • With any emacs on mac questions, it's helpful to identify the flavor of emacs. I'm guessing that @wsaleem uses emacs from https://emacsformacosx.com/ (as do I). Reading the contents of /Applications/Emacs.app/Contents/MacOS/Emacs, there's a descriptive comment from the maintainer about the purpose of the script. – Doug Harris Mar 31 '21 at 14:28

3 Answers3

198

Emacs.app actually launches using a ruby script. As a result, MacOS Catalina (or later, up to at least Ventura) uses the permissions set for ruby, not the permissions for Emacs.app. Open General Settings -> Security & Privacy -> Privacy, select Full Disk Access in the left pane, then click + and add /usr/bin/ruby to resolve your issue.

/usr is hidden by default on MacOS but you can toggle visibility in Finder by using Shift+Command+Period

Chris
  • 1,996
  • 1
  • 6
  • 2
  • 3
    Thank you! Worked great. I had to go back to "Security & Privacy" and click on General (after granting ruby access and trying emacs). And found that I had to "Allow apps downloaded from - App Store and identified developers. I ended up doing this twice. Looks like emacs is using some legacy stuff and that os x is checking more things that are not theirs. BUT worked great after that, so full access to ruby and then the legacy stuff and it worked. Outstanding post, thank you! – EvanCharlesSmith Oct 09 '19 at 11:59
  • 4
    @Chris's answer is right, or you can launch emacs in the terminal, which also resolves your problem. – Gilbert Wong Oct 09 '19 at 02:53
  • 7
    Is there a way to allow only a specific folder using "Files and Folders" instead of "Full Disk Access"? – Bee Nov 15 '19 at 16:22
  • 7
    I'm not sure it is so secure to give full access to any ruby script.... – larsr Jan 19 '20 at 20:28
  • Thank you very much! I had this problem exclusively for ~/Downloads directory. Could not list it in Dired mode (was getting "Listing directory failed but 'access-file' worked"). Interestingly, by launching Emacs without init file (`emacs -q`) I could still avoid running into this issue. Still don't understand why exactly Downloads folder that was off limits for Ruby, but at least it works now :) – honey_badger Jan 28 '20 at 13:01
  • 1
    If you run emacs in the terminal, you need to give access to the Terminal app or whichever terminal app you use. – nroose Mar 27 '20 at 04:25
  • 1
    N.B. This also works for Big Sur – randbw Nov 17 '20 at 15:53
  • Needed both /usr/bin/ruby and Applications/Emacs for Big Sur. – Dave X Oct 28 '21 at 01:54
  • Should we also give full disk permission to emacsclient? – alper Aug 22 '22 at 11:43
12

@Chris's answer also resolves a different problem for me (which had the same root cause): I'm recording it here to make this answer more findable.

I was getting the error "Listing directory failed but 'access-file' worked" on ~/Downloads (and Documents, Desktop, and some others). I tried adding Emacs to System Preferences > Security & Privacy > Full Disk Access, without success, as mentioned above. But adding /usr/bin/ruby solved it.

Sboisen
  • 151
  • 6
  • 2
    I used this to resolve the problem (also upvoted, b/c it solves the problem). HOWEVER, I feel like this is a security hole. I don't want *ruby* to have access to my entire computer. I'd just like Emacs to have access to my user directory, but that doesn't seem possible. I tried, but perhaps I don't know enough to know how to do it. – Andrew Philips Feb 15 '21 at 23:21
6

To get the full functionality of emacs back, I had to follow this document: https://spin.atomicobject.com/2019/12/12/fixing-emacs-macos-catalina/

All the other solutions did not fix the problem of clicking on a txt file with open emacs and opening the file within the open emacs.

Edit: As of May 2020 this seems to have stopped working. But here is a working solution: https://emacs.stackexchange.com/a/54383/2440

Stefan Müller
  • 303
  • 3
  • 8
  • 1
    Same. Just take care to `mv` the right binary. I had to mv the lower-numbered `*_10` binary instead of `*_14` to get things to work, as in the link, even on Catalina. Dunno why – Paul Sep 02 '20 at 01:11