NSWorkspace selectFile not work in today widget

I`m creating a macOS app with today widget, which has a feature that allow user reveal fold in finder.

My code is like this below:

let path = "/Users/"

print(NSWorkspace.shared().selectFile(nil, inFileViewerRootedAtPath: path))


It always return false and no finder window is opened when running in widget. But it works fine in my main app.

Is it a bug or something else?


I ask for help to the Apple Advisor, but they think it`s a code signing problem, so I come here for help.


My XCode version is 8A218a, my os version is 10.12.

Did you find any solutions? It does not work in the Settings scene in SwiftUI neither. It should show the content of the folder in finder according to this Stack Overflow post.

Button("Show in Finder") {
    let workspace = NSWorkspace.shared
    if let url = loadThisBookmark() {
        let result = workspace.selectFile(nil, inFileViewerRootedAtPath: url.path)
        if !result {
            logger.error("Cannot open \(url.path) in finder")
        }
    }
}
NSWorkspace selectFile not work in today widget
 
 
Q