import AppKit
|
import CoreGraphics
|
|
// Find visible windows across all apps
|
let apps = NSWorkspace.shared.runningApplications
|
|
// specifically look for Terminal
|
let terminalApps = apps.filter { app in
|
guard let name = app.localizedName else { return false }
|
return name.lowercased().contains("terminal")
|
}
|
|
print("Terminal-like apps found: \(terminalApps.count)")
|
for app in terminalApps {
|
print(" \(app.localizedName ?? "?") PID=\(app.processIdentifier)")
|
|
let axApp = AXUIElementCreateApplication(app.processIdentifier)
|
var windowsRef: CFTypeRef?
|
let result = AXUIElementCopyAttributeValue(axApp, kAXWindowsAttribute as CFString, &windowsRef)
|
|
if result == .success, let windows = windowsRef as? [AXUIElement] {
|
print(" Windows: \(windows.count)")
|
for (i, w) in windows.enumerated() {
|
var pos: CFTypeRef?, size: CFTypeRef?, title: CFTypeRef?
|
|
let titleResult = AXUIElementCopyAttributeValue(w, kAXTitleAttribute as CFString, &title)
|
let titleStr = (title as? String) ?? "(no title)"
|
|
var posVal = CGPoint.zero, sizeVal = CGSize.zero
|
let posOK = AXUIElementCopyAttributeValue(w, kAXPositionAttribute as CFString, &pos) == .success &&
|
AXValueGetValue(pos as! AXValue, .cgPoint, &posVal)
|
let sizeOK = AXUIElementCopyAttributeValue(w, kAXSizeAttribute as CFString, &size) == .success &&
|
AXValueGetValue(size as! AXValue, .cgSize, &sizeVal)
|
|
if posOK && sizeOK {
|
print(" [\(i)] \"\(titleStr)\" at (\(posVal.x), \(posVal.y)) size (\(sizeVal.width), \(sizeVal.height))")
|
}
|
|
// Min/Max
|
var minVal: CFTypeRef?, maxVal: CFTypeRef?
|
if AXUIElementCopyAttributeValue(w, "AXMinSize" as CFString, &minVal) == .success {
|
var minS = CGSize.zero
|
if AXValueGetValue(minVal as! AXValue, .cgSize, &minS) {
|
print(" MinSize: (\(minS.width), \(minS.height))")
|
}
|
}
|
if AXUIElementCopyAttributeValue(w, "AXMaxSize" as CFString, &maxVal) == .success {
|
var maxS = CGSize.zero
|
if AXValueGetValue(maxVal as! AXValue, .cgSize, &maxS) {
|
print(" MaxSize: (\(maxS.width), \(maxS.height))")
|
}
|
}
|
}
|
}
|
}
|
|
// All screens
|
for (i, screen) in NSScreen.screens.enumerated() {
|
print("Screen \(i):")
|
print(" frame=\(NSStringFromRect(screen.frame))")
|
print(" visibleFrame=\(NSStringFromRect(screen.visibleFrame))")
|
print(" safeAreaInsets.top=\(screen.safeAreaInsets.top)")
|
}
|