Skip to content

Commit f1a838f

Browse files
committed
Add apis for AXUIElement
1 parent 4edb610 commit f1a838f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Tool/Sources/AXExtension/AXUIElement.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ public extension AXUIElement {
8484
var isHidden: Bool {
8585
(try? copyValue(key: kAXHiddenAttribute)) ?? false
8686
}
87+
88+
var debugDescription: String {
89+
"<\(title)> <\(description)> (\(role):\(roleDescription)) [\(identifier)] \(rect ?? .zero) \(children.count) children"
90+
}
91+
92+
var debugEnumerateChildren: String {
93+
var result = "> " + debugDescription + "\n"
94+
result += children.map {
95+
$0.debugEnumerateChildren.split(separator: "\n")
96+
.map { " " + $0 }
97+
.joined(separator: "\n")
98+
}.joined(separator: "\n")
99+
return result
100+
}
87101
}
88102

89103
// MARK: - Rect
@@ -137,6 +151,15 @@ public extension AXUIElement {
137151
var isFullScreen: Bool {
138152
(try? copyValue(key: "AXFullScreen")) ?? false
139153
}
154+
155+
var windowID: CGWindowID? {
156+
var identifier: CGWindowID = 0
157+
let error = AXUIElementGetWindow(self, &identifier)
158+
if error == .success {
159+
return identifier
160+
}
161+
return nil
162+
}
140163

141164
var isFrontmost: Bool {
142165
get {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import AppKit
2+
3+
/// AXError _AXUIElementGetWindow(AXUIElementRef element, uint32_t *identifier);
4+
@_silgen_name("_AXUIElementGetWindow") @discardableResult
5+
func AXUIElementGetWindow(
6+
_ element: AXUIElement,
7+
_ identifier: UnsafeMutablePointer<CGWindowID>
8+
) -> AXError

0 commit comments

Comments
 (0)