How to open a folder via Finder using Swift in Xcode from a Finder Sync Extension

Viewed 2449

I am trying to open a specific folder when a user clicks on a menu item in the Finder Sync Extension I am writing. I know there are many similar questions posted because I have looked at them but none of the solutions are working in my application.

Here is the folder I am trying to open:

let folder = "/Users/username/some/folder"

This post, Show folder's contents in finder using Swift, suggested doing the following:

NSWorkspace.shared().selectFile(nil, inFileViewerRootedAtPath: folder)

When I tired this method, the menu item does nothing when it is clicked.

There are many other posts I have looked at and I have also tried the following methods but I haven't had anything work yet.

NSWorkspace.shared().activateFileViewerSelecting([URL(fileURLWithPath: safeZone, isDirectory: true)])

This results in the containing folder "some" being opened and the folder I actually wanted to open "folder" is just highlighted.

NSWorkspace.shared().openFile(safeZone)

When I tired this method, the menu item does nothing when it is clicked.

NSWorkspace.shared().open(URL(fileURLWithPath: safeZone, isDirectory: true))

When I tried this method, I got a message from Finder stating:

The application “MyAppFileSyncExtension” does not have permission to open “folder.”

Is there some way via Xcode to give the extension more permissions? I know my parent app can read and write to this folder no problem.

NSWorkspace.shared().openFile(folder, withApplication: "Finder")

When I tired this method, the menu item does nothing when it is clicked.

I am guessing that none of these methods are working because I am trying to do this from Finder Sync Extension. Does anyone know how to get around this issue?

UPDATE

I tested those methods from the parent application and most of them work. The question is how to create this type of behavior from a Finder Sync Extension. Any help would be greatly appreciated.

0 Answers
Related