hands test 2

This commit is contained in:
Ian Gulliver
2026-10-17 23:11:31 -07:00
parent ccf8c551ec
commit 39ca42316f
5 changed files with 21 additions and 18 deletions
+9 -12
View File
@@ -238,26 +238,23 @@ func axTreeTool(_ args: [String: Any]) async throws -> [Content] {
return [.text(try axTree(w, RefSource(pid: info.pid, window: id), treeOptions(args, origin: info.frame.origin)))]
}
func windowText(_ root: AXUIElement, contains needle: String) throws -> Bool {
func windowMatches(_ root: AXUIElement, _ needle: String) throws -> Int {
let n = needle.lowercased()
var visits = 0
func walk(_ e: AXUIElement) throws -> Bool {
var count = 0
func walk(_ e: AXUIElement) throws {
visits += 1
if visits > maxVisits {
return false
return
}
_ = try axRole(e)
for name in [kAXTitleAttribute, kAXDescriptionAttribute, kAXValueAttribute] {
if text(e, name).lowercased().contains(n) {
return true
}
if [kAXTitleAttribute, kAXDescriptionAttribute, kAXValueAttribute].contains(where: { text(e, $0).lowercased().contains(n) }) {
count += 1
}
for c in children(e) {
if try walk(c) {
return true
}
try walk(c)
}
return false
}
return try walk(root)
try walk(root)
return count
}