How to "Show in Finder"?

116 Views Asked by At

In SwiftUI for macOS, given a URL for a local file, I would like to be able to activate the Finder and open a window showing the file's enclosing folder, with the file selected.

In AppKit, this is the function of NSWorkspace's activateFileViewerSelecting(_:) method.

Does anyone know how to achieve the equivalent in native SwiftUI?

1

There are 1 best solutions below

0
Anton On

As @jnpdx pointed out, this is really an example where "the same old way" from AppKit works just fine:

NSWorkspace.shared.activateFileViewerSelecting([url])