Let’s focus on the app case for the moment. I took your code, tweaked it to use a path appropriate for my Mac, put it in a new app created from the macOS > App template, and ran it. As you reported, it failed to return any results. I then went to the App Sandbox slice of the Signing & Capabilities editor and changed the Pictures Folder popup to read-only. Now it prompts for access and produces results:
directory exists
["database", "Masters.legacy", "Plugins", "ProjectDBVersion.plist", "resources", "originals", "Data.noindex", ".ipspot_update", "Projects.db", "iPhotoLock.data", "Library6.iPhoto", "Library.iPhoto", "private", "Modified", "external", "Library.data", "iPhoto.ipspot", "Data", "iPhotoAux.db"]
I then created a new app, exactly as above, but this time I removed the App Sandbox slice from Signing & Capabilities and added the Hardened Runtime instead. The code returned no results again. However, I can regain access by checking Photo Library in the above-mentioned Hardened Runtime slice.
This is pretty much as I expected. There are two standard paths for apps to access the photo library:
So, are you planning to eventually ship an app? Or is a command-line tool your final product?
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
[1] A sandboxed app can be distributed via the Mac App Store but a non-sandboxed app must be distributed independently. Independent distribution requires notarisation and notarisation requires the hardened runtime.