Is is possible to capture the Mac OS X desktop without desktop items and any windows that may be open (i.e. just the wallpaper)?
I've experimented with CGWindowListCreateImage
, CGWindowListCreateImageFromArray
, and CGDisplayCreateImage
, but no luck.
Essentially I'm trying to capture the desktop wallpaper without using [NSWorkspace desktopImageURLForScreen:]
(it's a sandboxed app without access to the file system).
I know this is a super old question, and Tony Arnold's question is right, and what I used to build my own "grab the desktop" code.
I have some example code that shows how to do all these things (it's a wonderful thing walking in parts of Cocoa that are barely documented... )
I've put that sample code up in a bitbucket repository. Specifically the code sample to take a picture. (There's more interesting Cocoa code in my learning Cocoa repository, where that sample code is from )
Swift version:
You'll need to be careful to test that this is still correct, but the desktop window sits below the Finder (it's drawn by the Dock). Passing the
kCGWindowListOptionOnScreenBelowWindow
CGWindowListOption
toCGWindowListCreateImage
should get you what you want (unless something else is drawing below that level).Otherwise, you'll need to use
CGWindowListCreate
and iterate through the response excluding anything that isn't drawn by the dock at the window levelkCGMinimumWindowLevel + 19
.It gets kind of tricky when there are multiple screens, but hopefully this information is enough for you to do what you need.