0

In a macOS application written in Swift or Objective-C and targeted for the Mac App Store, how to determine programmatically if invisible files are currently shown in the Finder? I have tried to call defaults read com.apple.finder AppleShowAllFiles using NSTask, but it does not work in the sandbox. Any help is greatly appreciated, thanks.

zrzka
  • 20,249
  • 5
  • 47
  • 73
Alfonso Tesauro
  • 1,730
  • 13
  • 21
  • just out of curiosity: why would you need to know that? – vikingosegundo Jun 06 '20 at 15:56
  • 1
    You can’t. That’s the point of the sandbox. You can’t know anything about the internal state of another application, just as another sandboxed application can’t know about the state of your app. Finder at its heart is just another app. On the other hand if you can get your user to select that file in an open dialog you would have permission to read it. – Warren Burton Jun 06 '20 at 16:00
  • @vikingosegundo In my app, I have a simple "Show in Finder" feature that calls the well known NSWorkspace API. When the file is invisible, this feature does not work well, because the Finder selects the last visible item in the path. This could bring confusion for the user, so I am adding a check to see if the file is invisible and inform the user accordingly, but I would like to enforce it only if invisible files are not shown in the Finder because if they are, the Finder correctly selects the requested File/Folder. What do you think ? thanks for your comment. – Alfonso Tesauro Jun 06 '20 at 16:54
  • @WarrenBurton thanks a lot Warren, I had a feeling this was not possible, but who knows, there could have been a way, after all, it is not a feature that would really break the sandbox spirit. – Alfonso Tesauro Jun 06 '20 at 16:57

1 Answers1

0

Finder

It's irrelevant if com.apple.finder AppleShowAllFiles contains false or true. You probably misunderstood how it activates file viewer with URLs.

Example:

  • /Users/zrzka/.rustup
    • Finder is activated with content of the /Users/zrzka folder
    • .rustup folder is selected
  • /Users/zrzka/.rustup/toolchains
    • Finder is activated with content of the /Users/zrzka/.rustup folder
    • toolchains folder is selected

enter image description here

Sandbox

You can ask Apple for temporary exceptions. Here's more detailed answer. But it really depends on what files/folders do you want to reveal.

enter image description here

zrzka
  • 20,249
  • 5
  • 47
  • 73