GDAccessibilityObserver Class Reference

The GDAccessibilityObserver is an object oriented wrapper around accessibility notifications. More...

#import <GDAccessibilityObserver.h>

List of all members.

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.
NSStringnotification
 The notification name.
GDAccessibilityManageraccessManager
 Singleton instance of the GDAccessibilityManager.
GDAccessibilityNotificationnotify
 An instance of an GDAccessibilityNotification.

Detailed Description

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.

See also:
http://developer.apple.com/mac/library/documentation/Accessibility/Reference/AccessibilityLowlevel/AXUIElement_h/CompositePage.html#//apple_ref/c/func/AXObserverCreate
http://developer.apple.com/mac/library/documentation/Accessibility/Reference/AccessibilityLowlevel/AXUIElement_h/CompositePage.html#//apple_ref/c/func/AXObserverAddNotification
http://developer.apple.com/mac/library/documentation/Accessibility/Reference/AccessibilityLowlevel/AXUIElement_h/CompositePage.html#//apple_ref/c/func/AXObserverGetRunLoopSource
http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Miscellaneous/AppKit_Functions/Reference/reference.html#//apple_ref/c/func/NSAccessibilityPostNotification
Also see carbon run loops and CFRunLoopAddSource().

Member Function Documentation

- (id) initWithNotification: (NSString *)  notification
forAXUIElementRef: (AXUIElementRef)  element
callsAction: (SEL)  action
onTarget: (id)  target
withUserInfo: (NSDictionary *)  userInpho 

Designated initializer - init with required parameters.

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.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Enumerations Enumerator Properties Defines