I am trying to figure out how to get (read only) entire window/view hierarchy of any application. I get list of all open windows using CGWindowListCopyWindowInfo
. It also returns window number (kCGWindowNumber
). It also shows sharing status of root window by kCGWindowSharingState = 1;
. Now, I want to check that a particular window/view present in hierarchy of that application. I got kCGWindowNumber
which is root window of application.
Asked
Active
Viewed 1,563 times
6

Erik Kaplun
- 37,128
- 15
- 99
- 111

Suyash Patel
- 160
- 1
- 10
2 Answers
5
This is now possible via the View Debugging features of Xcode. To use this:
- Start the target app running as you normally would
- Launch Xcode, and open a project window (any project, might need to be OS X instead of iOS)
- Use the Debug > Attach To Process menu once it loads to select your target app
- Now click the little View Debugging button
or use the menu again: Debug > View Debugging > Capture View Hierarchy
This should show you a sort of "exploded" view of the app's views as well as a tree of their relationships in Xcode's left pane.

natevw
- 16,807
- 8
- 66
- 90
2
You really can't do this through Core Graphics, since the view hierarchy is entirely a Cocoa concept. You can do this through the Cocoa Scripting Bridge, possibly in combination with the GUI Automation support for Accessibility (here's example code for that).

Nikolai Ruhe
- 81,520
- 17
- 180
- 200

Mark Bessey
- 19,598
- 4
- 47
- 69
-
2[Here's sample code](https://developer.apple.com/library/mac/samplecode/UIElementInspector/Introduction/Intro.html) that get's you going. It's actually really easy and powerful. – Nikolai Ruhe Nov 05 '15 at 16:21
-
Nikolai, you should post that as an answer. And where were you a couple of months ago, when I could have really used this pointer? – Mark Bessey Nov 05 '15 at 20:30
-
1Thanks, I think your answer covers it. I added the link to make it more visible. – Nikolai Ruhe Nov 05 '15 at 20:45