43

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

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 1
    Welcome to emacs.SE! Can you `ls ~/Desktop` from a terminal? – JeanPierre Nov 21 '19 at 12:53
  • i can ls ~/Desktop, but first a popup appeared asking for permission –  Nov 22 '19 at 14:31
  • I found this: https://stackoverflow.com/questions/6192003/insecure-world-writable-dir-users-username-in-path-mode-040777-when-running-ru/6196644 And took the advice to take away write permission from my home folder: (from /Users): chmod go-w myusername – edj Mar 31 '21 at 21:04

4 Answers4

57

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.
masukomi
  • 105
  • 3
  • Can you get to them using a [remote-file name](https://www.gnu.org/software/emacs/manual/html_node/emacs/Remote-Files.html)? 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 '19 at 15:16
  • 1
    Does it help if you customize the variable `dired-use-ls-dired`? Try setting to `nil`. – John Palmieri Nov 22 '19 at 04:45
  • i haven't any clue what the remote file name is for my Desktop. i don't know what Tramp is either. i may be able to look into it later. i used M-x set-variable and typed in nil for dired-use-ls-dired but still have the same problem –  Nov 22 '19 at 14:38
  • 2
    Have you tried giving `ruby` full disk access? See https://emacs.stackexchange.com/questions/53026/how-to-restore-file-system-access-in-macos-catalina – John Palmieri Nov 22 '19 at 21:14
  • i haven't tried giving ruby full access. my question was simply "why" i couldn't access my Desktop, which i found the answer to. i've marked it as the answer. now as to "how" i can access it, the answer is in the link in my answer. i've tried it just now and it works! –  Nov 23 '19 at 12:47
  • Cmd+O doesn't really do anything for me in Emacs, but in the *GNU Emacs* home buffer there is an Open a File action where it says "To start…" And it seems to be creating a file so just give it a test name and hit Save. Then dired starts working again. – felideon May 04 '20 at 19:46
  • 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 '20 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 '21 at 11:53
13

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.

dns
  • 131
  • 1
  • 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 07 '20 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. – Kevin Buchs Sep 09 '21 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

spacegoing
  • 419
  • 2
  • 9
1

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

Vinh Trieu
  • 111
  • 1