I want to move a window with the Accessibility API.
With the following snippet
let options = CGWindowListOption(arrayLiteral: CGWindowListOption.excludeDesktopElements, CGWindowListOption.optionOnScreenOnly, CGWindowListOption.optionOnScreenAboveWindow)
let windowList = CGWindowListCopyWindowInfo(options, kCGNullWindowID) as NSArray? as? [[String: AnyObject]]
for entry in windowList!
{ if let bounds = entry[kCGWindowBounds as String] as? [String: Int],
let owner = entry[kCGWindowOwnerName as String] as? String,
let pid = entry[kCGWindowOwnerPID as String] as? Int32,
let windowNumber = entry[kCGWindowNumber as String] as? Int32
{ print("\(owner) (\(pid)-\(windowNumber))")
.....
the active windows are detected.
For some processes (e.g. notes), I get entries with the same pid but a different windowNumber. What I want, is to move a window with a given pid and windowNumber.
I tried with this snippet:
let appRef = AXUIElementCreateApplication(pid);
var value: AnyObject?
let result = AXUIElementCopyAttributeValue(appRef, kAXWindowsAttribute as CFString, &value)
if let windowList = value as? [AXUIElement]
{ ...
It returns a list of the windows of a process. I want to move one of these windows with a given windowNumber (from the snippet above)
How do I find that window?