Is it possible in swift to get a list of all apps with a window in the foreground and then set the size and position of these windows.
I get the list of windows properties like this
let type = CGWindowListOption.optionOnScreenOnly
let windowList = CGWindowListCopyWindowInfo(type, kCGNullWindowID) as NSArray? as? [[String: AnyObject]]
for entry in windowList!
{
var owner = entry[kCGWindowOwnerName as String] as! String
var bounds = entry[kCGWindowBounds as String] as? [String: Int]
var pid = entry[kCGWindowOwnerPID as String] as? Int32
print ("\(owner) \(bounds) \(pid) ")
if owner == "Erinnerungen"
{ bounds!["X"] = 0
bounds!["Y"] = 0
print("reset bounds")
let appRef = AXUIElementCreateApplication(pid!); //TopLevel Accessability Object of PID
print(appRef)
var value: AnyObject?
let result = AXUIElementCopyAttributeValue(appRef, kAXWindowsAttribute as CFString, &value)
if result == .success, let windowList = value as? [AXUIElement]
{ // DO ANYTHING
} else
{ print("Result no Success or no valid windowlist returnd")
}
}
}
Now I try to change some of the propierties, but that has no effect. Also trying to get the AttributeValue for the TopLevel Accessability Object of PID returns AXError (kAXErrorCannotComplete = -25204)