I am currently developing an Electron application with a companion Swift application that takes screenshots of the user's screen on keypress. It also takes a 1x1 pixel screenshot of the screen from time to time to figure out if a specific app is in dark mode.
After joining the latest macOS Sequoia beta, I've been seeing this permission pop up multiple times a day:
[App] can access this computer's screen and audio. Do you want to continue to allow access?
I think this is an unnecessary burden to my users especially after allowing it in the privacy settings. I want to get ahead of this and figure out if there is any way to get around having this shown multiple times a day.
I want the functionality to be when the user does allow permissions at the start of my app's onboarding, they never have to worry about it again.
func getPixelColor(at point: CGPoint) -> NSColor? {
let captureRect = CGRect(x: point.x, y: point.y, width: 1, height: 1)
guard let imageRef = CGWindowListCreateImage(captureRect, .optionOnScreenBelowWindow, kCGNullWindowID, [.nominalResolution]) else { return nil }
let bitmapRep = NSBitmapImageRep(cgImage: imageRef)
let color = bitmapRep.colorAt(x: 0, y: 0)
return color
}