The GDAccessibilityObserver is an object oriented wrapper around accessibility notifications. More...
#import <GDAccessibilityObserver.h>
Public Member Functions | |
| (id) | - initWithNotification:forAXUIElementRef:callsAction:onTarget:withUserInfo: |
| Designated initializer - init with required parameters. | |
| (NSInvocation *) | - invoker |
| [Internal] | |
Protected Attributes | |
| pid_t | app_pid |
| The application's pid. | |
| id | actionTarget |
| The target for the notification callback. | |
| SEL | actionSelector |
| The selector on the callback target. | |
| AXObserverRef | observer |
| An accessibility observer reference. | |
| AXUIElementRef | element |
| The accessibility element reference. | |
| NSInvocation * | invoker |
| An invoker that calls the target/selector when the accessibility notification occurs. | |
| NSMethodSignature * | selectorSignature |
| Method signature for the callback selector. | |
| NSDictionary * | userInfo |
| User info dictionary passed on notification. | |
| NSString * | notification |
| The notification name. | |
| GDAccessibilityManager * | accessManager |
| Singleton instance of the GDAccessibilityManager. | |
| GDAccessibilityNotification * | notify |
| An instance of an GDAccessibilityNotification. | |
The GDAccessibilityObserver is an object oriented wrapper around accessibility notifications.
It wraps a few function calls that create an accessibility observer: AXObserverCreate(), CFRunLoopAddSource(), AXObserverAddNotification() and AXObserverGetRunLoopSource().
Use this for notifications that post from accessibility objects. Accessibility notifications don't post from NSNotificationCenters, they post from the NSAccessibilityPostNotification() function.
Here's an extracted example of how you use it:
@implementation MyObject : NSObject - (id) initWithAppInfo:(NSDictionary *) appinfo { GDAccessibilityObserver * activated; //should be an instance variable if it needs to hang around in memory. GDAccessibilityManager * accessManager; //should be instance variable if(self = [self init]) { appInfo = [appinfo retain]; appPid = (pid_t)[[appInfo valueForKey:@"NSApplicationProcessIdentifier"] intValue]; GDAccessibilityOperationResult * appres = [accessManager applicationRefFromPid:appPid]; if([appres wasSuccess]) { appRef = (AXUIElementRef)[appres result]; CFRetain((CFTypeRef)appRef); activated = [[GDAccessibilityObserver alloc] initWithNotification:NSAccessibilityApplicationActivatedNotification forAXUIElementRef:appRef \ callsAction:@selector(applicationDidActivate:) onTarget:self withUserInfo:appInfo]; } else { return nil; } } return self; } @end
The important thing to remember is that it can subscribe to notifications from any AXUIElementRef. Use the GDAccessibilityManager to get the right reference you need.
| - (id) initWithNotification: | (NSString *) | notification | ||
| forAXUIElementRef: | (AXUIElementRef) | element | ||
| callsAction: | (SEL) | action | ||
| onTarget: | (id) | target | ||
| withUserInfo: | (NSDictionary *) | userInpho | ||
Designated initializer - init with required parameters.
| notification | The notification to subscribe to. | |
| element | The AXUIElementRef to listen for posted notifications from. | |
| action | A callback selector. | |
| target | A callback target object. | |
| userInpho | A user info dictionary. |
| - (NSInvocation *) invoker |
[Internal]
Returns the invoker for this observer.