I would like to give Desktop Access to my app using this pop up on launch for the first time exactly like Bridge does.
Do I need Privileged File Operation entitlement or is there a way to get around this without paying to become an apple developer?
I'm not planning on releasing my app on the Mac app store but it does need to be sandboxed due to using finder sync.
func applicationDidFinishLaunching(_ aNotification: Notification) {
let url = URL(fileURLWithPath: "/Users/useraccount/Desktop/", isDirectory: true)
let configuration: NSWorkspace.OpenConfiguration = NSWorkspace.OpenConfiguration()
configuration.promptsUserIfNeeded = true
let finder = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.finder")
NSWorkspace.shared.open([url], withApplicationAt: finder!, configuration: configuration)
}
This code only makes this pop up appear
Any help much appreciated.
If you could send me a code snippet
Sure. Here’s what I did this morning:
-
Using Xcode 14.3 on macOS 13.3.1, I created a new project from the macOS > App template, selecting SwiftUI.
-
In Signing & Capabilities I removed the App Sandbox, which the template adds by default.
-
I also check that automatic signing is enabled and my team selected. This results in the app being signed with my standard Apple Development signing identity.
-
I added a Test button that calls this function:
func test() { do { print("will find desktop") let desktop = try FileManager.default.url(for: .desktopDirectory, in: .userDomainMask, appropriateFor: nil, create: false) print("did find desktop, url: \(desktop)") print("will list contents") let contents = try FileManager.default.contentsOfDirectory(at: desktop, includingPropertiesForKeys: nil) print("did list contents, count: \(contents.count)") } catch { print("did fail") } }
-
I ran the app and clicked on the Test button. This presented the expected alert (screen shot below).
-
I clicked Allow. Back in Xcode I saw the app print:
will find desktop did find desktop, url: file:///Users/quinn/Desktop/ will list contents did list contents, count: 51
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"