How can I manipulate an outside app's windows' size?

Is there a way to monitor when the windows of a third-party app is moved about the screen and a way to change its size in real time? I looked through the accessibility API and it doesn't seem like manipulating the size is possible?

Replies

You can get the list of windows with their size and position:


https://stackoverflow.com/questions/50988659/how-to-get-the-list-of-open-windows-on-macos-in-swift


        let options = CGWindowListOption(arrayLiteral: .excludeDesktopElements, .optionOnScreenOnly)
        let windowsListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(0))
        let infoList = windowsListInfo as NSArray? as? [[String: AnyObject]]
        print(infoList)
        let visibleWindows = infoList?.filter{ $0["kCGWindowLayer"] as! Int == 0 }
        print("visibleWindows", visibleWindows)


gives info as:


"kCGWindowLayer": 0, "kCGWindowAlpha": 1, "kCGWindowOwnerName": Xcode, "kCGWindowSharingState": 1, "kCGWindowNumber": 6095, "kCGWindowStoreType": 1, "kCGWindowOwnerPID": 20494], ["kCGWindowOwnerPID": 20921, "kCGWindowBounds": {

Height = 1388;

Width = 2284;

X = 180;

Y = 44;

}, "kCGWindowName": How to get the list of open windows on MacOS in Swift? - Stack Overflow, "kCGWindowOwnerName": Safari Technology Preview, "kCGWindowAlpha": 1, "kCGWindowIsOnscreen": 1, "kCGWindowSharingState": 1, "kCGWindowNumber": 6165, "kCGWindowStoreType": 1, "kCGWindowMemoryUsage": 1248, "kCGWindowLayer": 0], ["kCGWindowStoreType": 2, "kCGWindowOwnerName": OpenOffice 4.1.6, "kCGWindowAlpha": 1, "kCGWindowMemoryUsage": 72811944, "kCGWindowSharingState": 1, "kCGWindowOwnerPID": 406, "kCGWindowLayer": 0, "kCGWindowBounds": {

Height = 1111;

Width = 2048;

X = 256;

Y = 137;

}

OK, thank you. Is there a way to know when any of these windows is being moved or do I have to keep this code in a polling loop? Can I programmatically alter the size of these windows? This is for the windows of other applications. This program itself won't have any windows. It would be a background app.

I have not found a way to get notified of change.

Have a look at Core Graphics > Quarz Window Service in XCode documentation > CGWindowListOption


So I guess you would have to poll for it.


I've not found either (and I am dubious it is possible through public API) how to modify other windows.

That would probably require low level data manipulation using non authorized API.


This in confirmed in this thread, which also give more insight.

Hope that can help.

https://stackoverflow.com/questions/17010638/osx-objective-c-window-management-manipulate-the-frames-visibility-of-other