42

When I do C-x C-f on ~/Desktop/ in macos Catalina, I get the following error.

Listing directory failed but 'access-file' worked

I can list the directory for just ~.

I'm new to Emacs and know little else. I've tried installing Emacs through Homebrew and using a binary from https://emacsformacosx.com

I've also searched for that error where some people said there's an issue with ls on mac, but I don't have any problem listing the contents of ~. Also, I didn't find any clear solution to that problem (I tried copy pasting answers to my init file but that didn't solve anything).

3
  • 1
    Welcome to emacs.SE! Can you ls ~/Desktop from a terminal?
    – JeanPierre
    Nov 21, 2019 at 12:53
  • i can ls ~/Desktop, but first a popup appeared asking for permission
    – user25536
    Nov 22, 2019 at 14:31
  • I found this: stackoverflow.com/questions/6192003/… And took the advice to take away write permission from my home folder: (from /Users): chmod go-w myusername
    – edj
    Mar 31, 2021 at 21:04

4 Answers 4

55

I found it. Apparently dired can't access icloud directories. My Desktop and Documents folders are sync'ed with icloud.

http://emacs.1067599.n8.nabble.com/iCloud-directory-access-issue-on-macOS-Catalina-td499227.html

If anyone comes here curious as to how they can access Desktop, Documents, or Downloads, the answer is in the link above, for reference, but I'll put it here in case that link expires.

  1. In System Preferences -> Security & Privacy, select the Privacy tab.
  2. From the list on the left, select Full Disk Access.
  3. Click the padlock in the lower left of the window to unlock this setting, if necessary.
  4. Click the + button to add Emacs to the list, then add Emacs.
  • Note: If it's already checked, try unchecking, allowing it to quit and restart emacs, then check it, and allow it to quit and restart emacs again.

Updating this answer since my original instructions aren't enough anymore. I had to also add ruby as others have pointed out in their answers.

  1. Click the + button to add /usr/bin/ruby, but the usr folder is hidden in the UI it pops up, so press Shift+Command+G to popup a thing where you can type in /usr/bin, and then select the ruby program.
8
  • Can you get to them using a remote-file name? Can you get to it with Tramp, otherwise than using Dired? If so then try the same (remote-file name) with Dired.
    – Drew
    Nov 21, 2019 at 15:16
  • 1
    Does it help if you customize the variable dired-use-ls-dired? Try setting to nil. Nov 22, 2019 at 4:45
  • 2
    Have you tried giving ruby full disk access? See emacs.stackexchange.com/questions/53026/… Nov 22, 2019 at 21:14
  • 4
    Cmd+O actually refers to s-u bound to ns-open-file-using-panel, if you didn't tweak your bindings. For those tilting your head on that one, use M-x ns-open-file-using-panel instead.
    – Dean Seo
    Dec 12, 2020 at 10:53
  • 1
    Note this is not related to iCloud - all macOS users will need to give Full Disk Access to access ~/Documents, ~/Desktop and ~/Downloads and some other directories under ~
    – mmmmmm
    Nov 21, 2021 at 11:53
12

If you find the problem persists after granting Emacs full disk access: from here on the problem remains because Emacs on MacOS gets launched indirectly, from a Ruby script. Your Emacs binary has full disk access, but Ruby does not.

One way to get around this is to get the Ruby script out of the way, and replace it with a symlink to the correct binary for your platform. See

https://github.com/caldwell/build-emacs/issues/84#issuecomment-545754668

for an example.

2
  • 2
    I was having trouble with auto-complete in C-x C-f even after granting Emacs full-disk access. I liked this proposal about the Ruby script being the problem, but I didn't like having to make the symlink, and remember to do that every time I updated Emacs. I just granted Ruby full-disk access so it's more permanent, if a little more insecure. It's a little more complicated to get to /usr inside the standard Open dialog (to add Ruby), but press Command-Shift-. (that's a period at the end) to see the hidden files (think of it the period as a "dot" and then think of "dot files").
    – jimtut
    Dec 7, 2020 at 16:23
  • At first I doubted, what was emacs doing with ruby scripts? But, then Homebrew packaging inserts those as an additional layer. Thanks. Sep 9, 2021 at 23:07
2

I followed Nabi and Vinh's solutions. dired worked but not all functions. For example, the sort is not working.

A quick search leads me here: https://github.com/d12frosted/homebrew-emacs-plus/issues/383#issuecomment-899157143

The problem is that macos's built-in ls does not support several flags dired+ use. What worked for me is following instructions here: https://stackoverflow.com/a/65112096/4062451

Notice that you might need to change the path insert-directory-program to where your brew is installed

1

In my case, just allow Full Disk for ruby (/usr/bin/ruby) then it works like charm!

1
  • After following Nabi's instructions my problem persists. This answer fixed it for me!
    – spacegoing
    Nov 21, 2021 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.