Universal Access on OSX


Does anybody have any experience programming accessibility-enabled applications on OSX?

I’ve been trying to programmatically control the zoom functionality that’s part of Universal Access - and, so far, I’ve been unable to find any examples of how this works.

The function UAZoomChangeFocus caught my attention: https://developer.apple.com/library/mac/documentation/ApplicationServices/Reference/UniversalAccess-header-reference/Reference/reference.html

It appears that one has to zoom in with the keyboard (command, option, +) for this function to work. In my tests, the function is not changing the zoom focus, but also isn’t returning any errors.

if( UAZoomEnabled() ){  
        // is this thing on?  
        ofRectangle zoom(ofGetFrameNum()%ofGetScreenWidth(), ofGetScreenHeight()/2, 200, 150);  
        ofRectangle window(0, 0, ofGetScreenWidth(), ofGetScreenHeight());  
        zoom = convertToScreenRect(zoom);  
        window = convertToScreenRect(window);  
        printf("zoom: %f %f %f %f\n", zoom.x, zoom.y, zoom.width, zoom.height); // << endl;  
        CGRect cgCaretRect = CGRectMake(zoom.x, zoom.y, zoom.width, zoom.height);  
        CGRect cgViewRect = CGRectMake(window.x, window.y, window.width, window.height);  
        //OSStatus err = UAZoomChangeFocus(&cgCaretRect, NULL, kUAZoomFocusTypeInsertionPoint);  
        OSStatus err = UAZoomChangeFocus(&cgViewRect, &cgCaretRect, kUAZoomFocusTypeOther);  
        printf("zoom? %i %i\n", err == noErr, err == paramErr);  

convertToScreenRect does the following:

ofRectangle testApp::convertToScreenRect(ofRectangle bounds){  
    bounds.y = ofGetScreenHeight() - ( bounds.y + bounds.height);  
    return bounds;  

I’m running this code in a ofxCocoaWindow, though I’m not sure if it’s necessary.

Perhaps this code will only work in a NSView object?

Thanks++ for any advice!


From the documentation, it sounds to me like UAZoomChangeFocus basically just scrolls the screen (if it is zoomed in) to ensure that the rectangles you pass in are visible. I don’t think it’s supposed to change the zoom factor. From what I can tell, Apple designed the accessibility system so that the zoom factor is under the user’s control, not the application’s.
You might have better luck with the Cocoa version of the accessibility API, it seems to be much more evolved than the old Carbon API (though I doubt you can zoom using it). See NSAccessibility.h or