API OS X Availability Minimum Width

I found another question explaining how to get the width, height and position of a window using the Accessibility API. Is there any way to find the minimum size, maximum size, resize, etc.?

Edit:

My current approach is to use AXUIElementCopyAttributeValue , but I'm not sure if this is possible. Looking at the reference , you can see that there are many properties that I can get, but I can’t find any mention of the minimum or maximum window size. Please note that this provision is available through this API.

Now I also looked at some example of the Son of Grab code, which can also access the size and position of the window, but I don’t know, t believe that the method works for the minimum or maximum size.

+7
source share
1 answer

As far as I can tell, there is no easy way. I found one very crude method for getting the maximum and minimum window size.

It includes setting the width and height to a very large number to see how far the window resizes, remembering that size as maximum, and then setting the width and height to a small number and doing the same thing again. In the end, I just reset the width and height to their original values.

The obvious problem is that it is very noticeable to the user that the window has been resized.

As for the resizing increments, I cannot come up with (at the moment) a workaround to get this information.

In any case, here is the code that I have for developing the maximum and minimum size:

 AXUIElementRef window; // The window AXValueRef sizeValue = (AXValueRef)[UIElementUtilities valueOfAttribute:@"AXSize" ofUIElement:window]; CGSize windowSize; AXValueGetValue(sizeValue, kAXValueCGSizeType, &windowSize); CGFloat windowWidth = windowSize.width; CGFloat windowHeight = windowSize.height; // Set it to a very large number [UIElementUtilities setStringValue:@"w=5000 h=5000" forAttribute:@"AXSize" ofUIElement:window]; AXValueRef maxSizeValue = (AXValueRef)[UIElementUtilities valueOfAttribute:@"AXSize" ofUIElement:window]; CGSize maxWindowSize; AXValueGetValue(maxSizeValue, kAXValueCGSizeType, &maxWindowSize); CGFloat maxWindowWidth = maxWindowSize.width; CGFloat maxWindowHeight = maxWindowSize.height; NSLog(@"max width = %f. max height = %f.", maxWindowWidth, maxWindowHeight); // Set it to a very small number [UIElementUtilities setStringValue:@"w=0 h=0" forAttribute:@"AXSize" ofUIElement:window]; AXValueRef minSizeValue = (AXValueRef)[UIElementUtilities valueOfAttribute:@"AXSize" ofUIElement:window]; CGSize minWindowSize; AXValueGetValue(minSizeValue, kAXValueCGSizeType, &minWindowSize); CGFloat minWindowWidth = minWindowSize.width; CGFloat minWindowHeight = minWindowSize.height; NSLog(@"min width = %f. min height = %f.", minWindowWidth, minWindowHeight); // Reset size [UIElementUtilities setStringValue:[NSString stringWithFormat:@"w=%fh=%f", windowWidth, windowHeight] forAttribute:@"AXSize" ofUIElement:window]; 

If you're interested, UIElementUtilities is the class I took from one of Apple's projects called UIElementInspector .

+3
source

All Articles