In a WWDC 2019 "Advances in macOS Security" at 18:40 there is the following code
func getDesktopWindowIds() -> [CGWindowID] {
let windows = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID)! as! [[String: AnyObject]]
let DesktopWindowLevel = CGWindowLevelForKey(.desktopWindow)-1
let DesktopWindows = windows.filter {
let windowLevel = $0[kCGWindowLayer as String] as! CGWindowLevel
return windowLevel == desktopWindowLevel
}
return desktopWindows.map {
$0[kCGWindowNumber as String] as! CGWindowID
}
}
to find the CGWindowID of the Desktop background. This works, but when you then try to get the CGImage for that CGWindowID with
let cgImage = CGWindowListCreateImage(CGRectNull, [.optionIncludingWindow], cgWin, [.bestResolution])
cgImage does get a reference, however it's just a gray image. Not the Desktop picture.
It's clear from the documentation that ScreenCaptureKit should be used.
However, if used I get multiple warnings to the user, the most concerning one states:
"App" would like to record this computer's screen and audio.
This is not true! I do nothing with audio and to say a capture is a recording is also misleading.
Is there way to achieve what use to work before macOS 27? Or a way to change/avoid this misleading warning? Is there a reason why this warning is needed for capturing the Desktop background where before it was explicitly allowed?
Thanks for tracking down where that code came from, and for posting your ScreenCaptureKit version.
What you describe is a change between releases: the same CGWindowListCreateImage call returned the desktop picture through macOS 26 and returns a gray image on macOS 27. I don't have a way to get the earlier result on macOS 27, and I can't comment on the reasons behind the change.
I also can't offer a way to capture with ScreenCaptureKit without the alert. The alert is how the person grants that access.
I suggest filing two separate Feedback Assistant reports:
- one about the
CGWindowListCreateImagechange, showing what it returns for the same desktop background window on macOS 26 and on macOS 27 - one about the Screen Recording alerts your app triggers, describing their text and what your app captures
Please post the Feedback numbers here so we can make sure they get routed to the right team. If you're not familiar with filing reports, take a look at Bug Reporting: How and Why?
For the first-run problem, the Capturing screen content in macOS sample notes: "After you grant permission, you need to restart the app to enable capture."
I also replied in your related thread, ScreenCaptureKit is NOT a full replacement for CGWindowListCreateImage, which covers the sharing picker and an enhancement request for a narrower grant.