3 Replies
      Latest reply on Nov 7, 2019 11:35 PM by Claude31
      mauricev Level 1 Level 1 (0 points)

        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?

        • Re: How can I manipulate an outside app's windows' size?
          Claude31 Level 8 Level 8 (6,965 points)

          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;

          }