Question

In my app I want to check if windows from others apps are resizable.

I´m using the accessibility API to test if the window has the kAXGrowAreaAttribute attribute (if NULL is not resizable) as Peter Hosey answered in this question.

The problem is that the kAXGrowAreaAttribute returned value is always NULL it doesn´t matter if the window is resizable or not. Note: to retrieve the value I´m using the UIElementUtilities class from the Apple UIElementInspector example (I also have tried using AXUIElementCopyAttributeValue directly with the same result).

Any idea? I´m working in Lion, could be this the problem? Thanks in advance.

EDITED:

Playing around with the UIElementUtilities class methods I found a solution.

Just use the method

+ (BOOL)canSetAttribute:(NSString *)attributeName ofUIElement:(AXUIElementRef)element

with the kAXSizeAttribute and the focused window. It returns YES or NO depending if the window is sizable or not...

Was it helpful?

Solution

It probably is because you're in Lion. The size box was killed off; resizable windows are resizable at every edge now.

And yes, testing whether the size can be changed is probably the right way. It seems to work for me in Snow Leopard.

OTHER TIPS

Swift 5 version:

func isResizable(axElement: AXUIElement) -> Bool {
    var resizable: DarwinBoolean = true
    let status = AXUIElementIsAttributeSettable(axElement, kAXSizeAttribute as CFString, &resizable)

    if status != .success {
        print("unable to determine if window is resizable")
    }
    return resizable.boolValue
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top