PFObserver
IntroductionA concrete class representing an observer that may be registered to observe changes to UI elements in a running application. DiscussionA PFObserver object represents an observer that may be registered to observe changes to UI elements on the screen in a running application, such as a menu, window or button. The PFObserver class implements all of the functionality of the accessibility API's AXObserverRef object. It declares a delegate method, -applicationWithIdentifier:atPath:didPostAccessibilityNotification:fromObservedUIElement:forAffectedUIElement: that a client application can implement to monitor and respond to accessibility notifications. As an alternative, it permits you to write a similar callback method using Objective-C. In this documentation "observer" refers to a programmatic PFObserver object. Depending on context, "UI element" or "element" may refer to a programmatic PFUIElement or PFApplicationUIElement object or to the user interface object in the running application that is represented by a PFUIElement or PFApplicationUIElement object. References to a "PFUIElement object" generally include a PFApplicationUIElement object, since the PFApplicationUIElement class is a subclass of PFUIElement. A PFObserver object can register to receive various notifications that are posted by UI elements in any running application when they change state; for example, when an application is activated or a window is closed. When an observer has registered for a notification, a client's delegate method or callback method is triggered to take any desired action in response to the change in the observed UI element. You can create multiple observers and register each of them for one or more notifications, but it is usually easier to register a single observer in an application and register it for all of the notifications of interest. Observers can be unregistered at will for individual notifications or for all of them. Observers maintain lists of all of their current registrations. When they change state, accessibility API objects post notifications identified by a string, usually beginning with the prefix "AX" as in "AXWindowCreated". In a client application, you normally use the NSString constants declared in the NSAccessibility informal protocol (in NSAccessibility.h, in the Cocoa AppKit framework). Alternatively, you can use the corresponding CFStringRef constants declared in the accessibility API headers and cast them to NSString*, or use the string itself. Some constants are omitted from NSAccessibility.h or from the accessibility API headers; if you can't find a desired constant in one of these headers, use a constant from the other header or the string itself. Note that some constants in these headers may be marked as obsolete; use only the non-obsolete constants or their string equivalents to maximize compatibility with future releases of macOS. Some applications implement custom UI elements. Although Apple discourages the invention of new notifications, some applications may implement custom notifications that are not part of Apple's accessibility API. This framework is written so that you can read and manipulate them, as well as Apple's built-in accessibility API notifications. You may be able to identify the strings used to identify custom notifications by reading an application's documentation or by examining the .strings files in its application bundle. The accessibility API currently offers no means to obtain a list of available notifications programmatically. Public methods in the PFAssistive framework, unless otherwise noted, take Objective-C objects as parameters and, when they return Objective-C objects, return them autoreleased. Clients of the PFAssistive framework should not have to deal with Core Foundation objects. Unless otherwise noted, methods with return values return Almost all standard UI element objects in Cocoa and Carbon applications come prewired to post notifications when they change state. Custom UI elements may have been written to post notifications, as well. However, there are many applications that do not use standard UI elements or that use custom elements that do not support the accessibility API. The only way to know which of an application's UI elements support the accessibility API is trial and error and, in some cases, an application's documentation. The following notifications were introduced in OS X Mavericks 10.9: NSAccessibilityAnnouncementRequestedNotification and NSAccessibilityLayoutChangedNotification. Before a client application can make use of this class in OS X Mavericks 10.9 or later, access must be granted to it in the Accessibility list in the Security & Privacy preference's Privacy pane in System Preferences. In OS X Mountain Lion 10.8 or earlier, the "Enable access for assistive devices" setting in the Accessibility (or Universal Access) pane of System Preferences must be turned on, or the client application must be made a trusted process through use of the accessibility API's GroupsDELEGATE ACCESSORSGroup members:
INITIALIZATIONGroup members:
UTILITIESGroup members:
DEBUGGING UTILITIESGroup members:
CLASS UTILITY METHODSGroup members:
ACCESSORSGroup members:
REGISTRATIONGroup members:
Methods
delegateReturns the receiver's delegate. - (nullable id <PFObserverDelegate>)delegate; Return ValueThe receiver's delegate, an object of any type, or DiscussionThe only available delegate messages are -applicationWithIdentifier:atPath:didPostAccessibilityNotification:fromObservedUIElement:forAffectedUIElement: and -applicationWithIdentifier:atPath:didPostAccessibilityNotification:fromObservedUIElement:forAffectedUIElement:withInfo:, both of which are optional. They are declared in the PFObserverDelegate protocol. See -setDelegate: for more information. descriptionReturns a string that represents the receiver. - (NSString *)description; Return ValueAn NSString object. DiscussionThe returned string is formatted as a property list showing all notifications for all UI elements for which the observer is registered. In client code, call initForInfoWithBundleIdentifier:Initializes and returns a newly allocated PFObserver object that uses a delegate method and includes an info dictionary with - (nullable instancetype)initForInfoWithBundleIdentifier:(nullable NSString *)bundleIdentifier; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer to initialize a newly-allocated observer that uses a delegate method instead of a callback method and includes an info dictionary to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initForInfoWithPid: for important information about creating new observer objects. See also -initForInfoWithPath: , -initForInfoWithURL: and -initForInfoWithPid:. initForInfoWithBundleIdentifier:notificationDelegate:infoCallbackSelector:Initializes and returns a newly allocated PFObserver object that uses a callback method that includes an info dictionary with - (nullable instancetype)initForInfoWithBundleIdentifier:(nullable NSString *)bundleIdentifier notificationDelegate:(nullable id)callbackDelegate infoCallbackSelector:(nullable SEL)callback; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer to initialize a newly-allocated application observer object that uses a callback method instead of a delegate method and includes an info dictionary to respond to accessibility notifications. A client application must call -registerForNotification:fromElement:contextInfo: in order to receive notifications. See the designated initializer -initWithPid:notificationDelegate:callbackSelector: for important information about creating new observer objects. See also -initForInfoWithPath:notificationDelegate:infoCallbackSelector: , -initForInfoWithURL:notificationDelegate:infoCallbackSelector: and -initForInfoWithPid:notificationDelegate:infoCallbackSelector:. initForInfoWithPath:Initializes and returns a newly allocated PFObserver object that uses a delegate method and includes an info dictionary with - (nullable instancetype)initForInfoWithPath:(nullable NSString *)fullPath; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer to initialize a newly-allocated observer that uses a delegate method instead of a callback method and includes an info dictionary to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initForInfoWithPid: for important information about creating new observer objects. See also -initForInfoWithURL: , -initForInfoWithBundleIdentifier: and -initForInfoWithPid:. initForInfoWithPath:notificationDelegate:infoCallbackSelector:Initializes and returns a newly allocated PFObserver object that uses a callback method that includes an info dictionary with - (nullable instancetype)initForInfoWithPath:(nullable NSString *)fullPath notificationDelegate:(nullable id)callbackDelegate infoCallbackSelector:(nullable SEL)callback; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer or the designated initializer -initWithPid:notificationDelegate:callbackSelector: to initialize a newly-allocated application observer object that uses a callback method instead of a delegate method and includes an info dictionary to respond to accessibility notifications. A client application must call -registerForNotification:fromElement:contextInfo: in order to receive notifications. See the designated initializer -initWithPid:notificationDelegate:callbackSelector: for important information about creating new observer objects. See also -initForInfoWithURL:notificationDelegate:infoCallbackSelector: , -initForInfoWithBundleIdentifier:notificationDelegate:infoCallbackSelector: and -initForInfoWithPid:notificationDelegate:infoCallbackSelector:. initForInfoWithPid:Initializes and returns a newly allocated PFObserver object that includes an info dictionary with - (nullable instancetype)initForInfoWithPid:(pid_t)pid; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this initializer to initialize a newly-allocated application observer object that uses a delegate method instead of a callback method and includes an info dictionary to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. A client application normally creates new PFObserver objects without using this method directly, instead using the +observerWithPath: , +observerWithURL: , +observerWithBundleIdentifier: or +observerWithPid: class method. The class methods are strongly preferred because they set up private data structures that automatically manage observers. An observer does nothing unless it has been registered to receive at least one notification with respect to at least one observed UI element of the target application, using -registerForNotification:fromElement:contextInfo:. There can be multiple observers for any one target application, but it is normally sufficient to create one observer per target application and register it for multiple notifications. If you use one of the PFObserver factory methods, such as the +observerWithURL: class method, to create an observer, the observer is managed for you. When an observer receives a notification from an observed element, it sends the -applicationWithIdentifier:atPath:didPostAccessibilityNotification:fromObservedUIElement:forAffectedUIElement:withInfo: delegate message, passing the target application's identifier and path, the notification, the observed UI element, the affected UI element (which may differ from the element being observed), and the notification info dictionary. The client's delegate method will always receive the affected element, even when observing If a delegate method initiates a time-consuming operation or an operation that might fail, consider executing the operation in a secondary thread using a method like NSThread's All observers maintain a list of the notifications and elements for which they are currently registered. See -registrations for details. See also -initForInfoWithPath: , -initForInfoWithURL: and -initForInfoWithBundleIdentifier:. initForInfoWithPid:notificationDelegate:infoCallbackSelector:The designated initializer for the PFObserver class for an observer that uses a callback method that includes an info dictionary. Initializes and returns a newly allocated PFObserver object with - (nullable instancetype)initForInfoWithPid:(pid_t)pid notificationDelegate:(nullable id)callbackDelegate infoCallbackSelector:(nullable SEL)callback NS_DESIGNATED_INITIALIZER; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this designated initializer to initialize a newly-allocated application observer object that uses an info callback method instead of a delegate method and includes an info dictionary to respond to accessibility notifications. This method covers the AXObserverCreateWithInfoCallback function introduced in Mac OS X 10.7 (Lion) and first made public in OS X Mavericks 10.9. This method is identical to -initWithPid:notificationDelegate:callbackSelector: except that, instead of using a normal callback selector, it uses an enhanced callback selector returning an info dictionary provided by certain notifications. Applications may post notifications that include an info dictionary. The new NSAccessibilityLayoutChangedNotification notification may be posted by an application that uses the new AXShowAlternateUI and AXShowDefaultUI actions to show or hide transient UI elements, and the new NSAccessibilityAnnouncementRequestedNotification notification may be posted by an application to request that an announcement be made to the user by an assistive application such as VoiceOver. The info dictionary in the former notification contains an array listing the UI elements that have changed for the key NSAccessibilityLayoutChangedNotification. The info dictionary in the latter notification contains the announcement as a localized string for the key NSAccessibilityAnnouncementRequestedNotification. When an observer receives one of these notifications from an observed element, it invokes the specified info callback selector on the notification delegate. It passes back to the client's callback method the observer, the notification, the affected UI element (which may differ from the element being observed), the info dictionary provided by the notification, and any context information that was provided by the client when it registered the observer for the notification. The client's callback selector should have the following signature:
See -initWithPid:notificationDelegate:callbackSelector: for more information. initForInfoWithURL:Initializes and returns a newly allocated PFObserver object that uses a delegate method and includes an info dictionary with - (nullable instancetype)initForInfoWithURL:(nullable NSURL *)url; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer to initialize a newly-allocated observer that uses a delegate method instead of a callback method and includes an info dictionary to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initForInfoWithPid: for important information about creating new observer objects. See also -initForInfoWithPath: , -initForInfoWithBundleIdentifier: and -initForInfoWithPid:. initForInfoWithURL:notificationDelegate:infoCallbackSelector:Initializes and returns a newly allocated PFObserver object that uses a callback method that includes an info dictionary with - (nullable instancetype)initForInfoWithURL:(nullable NSURL *)url notificationDelegate:(nullable id)callbackDelegate infoCallbackSelector:(nullable SEL)callback; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer to initialize a newly-allocated application observer object that uses a callback method instead of a delegate method and includes an info dictionary to respond to accessibility notifications. A client application must call -registerForNotification:fromElement:contextInfo: in order to receive notifications. See the designated initializer -initWithPid:notificationDelegate:callbackSelector: for important information about creating new observer objects. See also -initForInfoWithPath:notificationDelegate:infoCallbackSelector: , -initForInfoWithBundleIdentifier:notificationDelegate:infoCallbackSelector: and -initForInfoWithPid:notificationDelegate:infoCallbackSelector:. initWithBundleIdentifier:Initializes and returns a newly allocated PFObserver object with - (nullable instancetype)initWithBundleIdentifier:(nullable NSString *)bundleIdentifier; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer to initialize a newly-allocated observer that uses a delegate method instead of a callback method to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initWithPid: for important information about creating new observer objects. See also -initWithPath: , -initWithURL: and -initWithPid:. initWithBundleIdentifier:notificationDelegate:callbackSelector:Initializes and returns a newly allocated PFObserver object with - (nullable instancetype)initWithBundleIdentifier:(nullable NSString *)bundleIdentifier notificationDelegate:(nullable id)callbackDelegate callbackSelector:(nullable SEL)callback; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer to initialize a newly-allocated application observer object that uses a callback method instead of a delegate method to respond to accessibility notifications. A client application must call -registerForNotification:fromElement:contextInfo: in order to receive notifications. See the designated initializer -initWithPid:notificationDelegate:callbackSelector: for important information about creating new observer objects. See also -initWithPath:notificationDelegate:callbackSelector: , -initWithURL:notificationDelegate:callbackSelector: and -initWithPid:notificationDelegate:callbackSelector:. initWithPath:Initializes and returns a newly allocated PFObserver object with - (nullable instancetype)initWithPath:(nullable NSString *)fullPath; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer to initialize a newly-allocated observer that uses a delegate method instead of a callback method to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initWithPid: for important information about creating new observer objects. See also -initWithURL: , -initWithBundleIdentifier: and -initWithPid:. initWithPath:notificationDelegate:callbackSelector:Initializes and returns a newly allocated PFObserver object with - (nullable instancetype)initWithPath:(nullable NSString *)fullPath notificationDelegate:(nullable id)callbackDelegate callbackSelector:(nullable SEL)callback; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer or the designated initializer -initWithPid:notificationDelegate:callbackSelector: to initialize a newly-allocated application observer object that uses a callback method instead of a delegate method to respond to accessibility notifications. A client application must call -registerForNotification:fromElement:contextInfo: in order to receive notifications. See the designated initializer -initWithPid:notificationDelegate:callbackSelector: for important information about creating new observer objects. See also -initWithURL:notificationDelegate:callbackSelector: , -initWithBundleIdentifier:notificationDelegate:callbackSelector: and -initWithPid:notificationDelegate:callbackSelector:. initWithPid:Initializes and returns a newly allocated PFObserver object with - (nullable instancetype)initWithPid:(pid_t)pid; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer to initialize a newly-allocated application observer object that uses a delegate method instead of a callback method to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. A client application normally creates new PFObserver objects without using an initializer method directly, instead using the +observerWithPath: , +observerWithURL: , +observerWithBundleIdentifier: or +observerWithPid: class factory method. The class methods are strongly preferred because they set up private data structures that automatically manage observers. An observer does nothing unless it has been registered to receive at least one notification with respect to at least one observed UI element of the target application, using -registerForNotification:fromElement:contextInfo:. There can be multiple observers for any one target application, but it is normally sufficient to create one observer per target application and register it for multiple notifications. If you use one of the PFObserver factory methods, such as the +observerWithURL: class method, to create an observer, the observer is managed for you. When an observer receives a notification from an observed element, it sends the -applicationWithIdentifier:atPath:didPostAccessibilityNotification:fromObservedUIElement:forAffectedUIElement: delegate message, passing the target application's identifier and path, the notification, the observed UI element, and the affected UI element (which may differ from the element being observed). The client's delegate method will always receive the affected element, even when observing If a delegate method initiates a time-consuming operation or an operation that might fail, consider executing the operation in a secondary thread using a method like NSThread's All observers maintain a list of the notifications and elements for which they are currently registered. See -registrations for details. See also -initWithPath: , -initWithURL: and -initWithBundleIdentifier:. initWithPid:notificationDelegate:callbackSelector:The designated initializer for the PFObserver class for an observer that uses a callback method. Initializes and returns a newly allocated PFObserver object with - (nullable instancetype)initWithPid:(pid_t)pid notificationDelegate:(nullable id)callbackDelegate callbackSelector:(nullable SEL)callback NS_DESIGNATED_INITIALIZER; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this designated initializer to initialize a newly-allocated application observer object that uses a callback method instead of a delegate method to respond to accessibility notifications. This method covers the AXObserverCreate function. Although this is a designated initializer for the PFObserver class, a client application normally creates new PFObserver objects without using this method directly, instead using the +observerWithPath:notificationDelegate:callbackSelector: , +observerWithURL:notificationDelegate:callbackSelector: , +observerWithBundleIdentifier:notificationDelegate:callbackSelector: or the +observerWithPid:notificationDelegate:callbackSelector: class method. The class methods are strongly preferred because they set up private data structures that automatically manage observers. An observer does nothing unless it has been registered to receive at least one notification with respect to at least one observed UI element of the target application, using -registerForNotification:fromElement:contextInfo:. There can be multiple observers for any one target application, but it is normally sufficient to create one observer per target application and register it for multiple notifications. If you use one of the PFObserver factory methods, such as the +observerWithURL:notificationDelegate:callbackSelector: class method to create an observer, the observer is managed for you. When an observer receives a notification from an observed element, it invokes the specified callback selector on the notification delegate. It passes back to the client's callback method the observer, the notification, the affected UI element (which may differ from the element being observed), and any context information that was provided by the client when it registered the observer for the notification. A notification delegate is temporary; the relationship only lasts until the observer is deallocated. The client's callback selector should have the following signature:
The client's callback method will always receive the affected element, even when observing If a callback method initiates a time-consuming operation or an operation that might fail, consider executing the operation in a secondary thread using a method like NSThread's All observers maintain a list of the notifications and elements for which they are currently registered. See -registrations for details. If you allocate your own observer and use this method to initialize it, you must manage the observer yourself. It is the client's responsibility to keep track of each observer created in this manner, retaining it as long as it is in use; to register and unregister it for notifications and elements as desired; to release it when done with it; and to maintain a list of its current registrations. See also -initWithPath:notificationDelegate:callbackSelector:, -initWithURL:notificationDelegate:callbackSelector: and -initWithBundleIdentifier:notificationDelegate:callbackSelector:. initWithURL:Initializes and returns a newly allocated PFObserver object with - (nullable instancetype)initWithURL:(nullable NSURL *)url; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer to initialize a newly-allocated observer that uses a delegate method instead of a callback method to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initWithPid: for important information about creating new observer objects. See also -initWithPath: , -initWithBundleIdentifier: and -initWithPid:. initWithURL:notificationDelegate:callbackSelector:Initializes and returns a newly allocated PFObserver object with - (nullable instancetype)initWithURL:(nullable NSURL *)url notificationDelegate:(nullable id)callbackDelegate callbackSelector:(nullable SEL)callback; ParametersReturn ValueAn initialized PFObserver object, or DiscussionUse this convenience initializer to initialize a newly-allocated application observer object that uses a callback method instead of a delegate method to respond to accessibility notifications. A client application must call -registerForNotification:fromElement:contextInfo: in order to receive notifications. See the designated initializer -initWithPid:notificationDelegate:callbackSelector: for important information about creating new observer objects. See also -initWithPath:notificationDelegate:callbackSelector: , -initWithBundleIdentifier:notificationDelegate:callbackSelector: and -initWithPid:notificationDelegate:callbackSelector:. invalidateInvalidates this PFObserver object when it is no longer needed. - (void)invalidate; DiscussionOptionally call this method when the client application is finished with this PFObserver object. Call this method as soon as this PFObserver object is no longer needed in order to avoid adding time-consuming activity at dealloc time. If the client application does not call this method, it will be called automatically when the object is deallocated. It sets any delegate to NOTE: PFAssistive Framework does not support garbage collected clients. See also -isValid. isEqualToObserver:Returns whether the receiving observer represents the same observer that - (BOOL)isEqualToObserver:(PFObserver *)observer; ParametersDiscussionReturns Use this method for efficiency if you know that observer is a PFObserver object. Otherwise, use isRegisteredForNotification:fromElement:Returns - (BOOL)isRegisteredForNotification:(NSString *)notification fromElement:(nullable PFUIElement *)element; ParametersDiscussionReturns Use this method at any time to test whether a particular element is registered with the receiver for a particular notification. It always returns See also -registerForNotification:fromElement:contextInfo:, -unregisterForNotification:fromElement:, -unregisterForAllNotificationsFromElement: and -unregisterForAllNotifications. isValidReports whether this PFObserver object has been initialized and has not been invalidated. - (BOOL)isValid; DiscussionReturns See also -invalidate. observerForInfoWithBundleIdentifier:Convenience class method creates and returns an initialized PFObserver object that uses a delegate method and includes an info dictionary with + (nullable instancetype)observerForInfoWithBundleIdentifier:(nullable NSString *)bundleIdentifier; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this convenience method to create an observer that uses a delegate method instead of a callback method and includes an info dictionary to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initForInfoWithPid: for important information about creating new observer objects. See also +observerForInfoWithPath: , +observerForInfoWithURL: and +observerForInfoWithPid:. observerForInfoWithBundleIdentifier:notificationDelegate:infoCallbackSelector:Convenience class method creates and returns an initialized PFObserver object that uses a callback method that includes an info dictionary with + (nullable instancetype)observerForInfoWithBundleIdentifier:(nullable NSString *)bundleIdentifier notificationDelegate:(nullable id)callbackDelegate infoCallbackSelector:(nullable SEL)callback; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this method to create an observer for a specific application given its name and to set up automatic management of the observer, for an observer that uses a callback method instead of a delegate method and includes an info dictionary to respond to accessibility notifications. See the designated initializer, -initForInfoWithPid:notificationDelegate:infoCallbackSelector:, for full information about use of this method. See also +observerForInfoWithPath:notificationDelegate:infoCallbackSelector: , +observerForInfoWithURL:notificationDelegate:infoCallbackSelector: and +observerForInfoWithPid:notificationDelegate:infoCallbackSelector:. observerForInfoWithPath:Convenience class method creates and returns an initialized PFObserver object that uses a delegate method and includes an info dictionary with + (nullable instancetype)observerForInfoWithPath:(nullable NSString *)fullPath; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this convenience method to create an observer that uses a delegate method instead of a callback method and includes an info dictionary to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initForInfoWithPid: for important information about creating new observer objects. See also +observerForInfoWithURL: , +observerForInfoWithBundleIdentifier: and +observerForInfoWithPid:. observerForInfoWithPath:notificationDelegate:infoCallbackSelector:Convenience class method creates and returns an initialized PFObserver object that uses a callback method that includes an info dictionary with + (nullable instancetype)observerForInfoWithPath:(nullable NSString *)fullPath notificationDelegate:(nullable id)callbackDelegate infoCallbackSelector:(nullable SEL)callback; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this method to create an observer for a specific application given its name and to set up automatic management of the observer, for an observer that uses a callback method instead of a delegate method and includes an info dictionary to respond to accessibility notifications. See the designated initializer, -initForInfoWithPid:notificationDelegate:infoCallbackSelector:, for full information about use of this method. See also +observerForInfoWithURL:notificationDelegate:infoCallbackSelector: , +observerForInfoinitWithBundleIdentifier:notificationDelegate:infoCallbackSelector: and +observerForInfoWithPid:notificationDelegate:infoCallbackSelector:. observerForInfoWithPid:Convenience class method creates and returns an initialized PFObserver object that uses a delegate method and includes an info dictionary with + (nullable instancetype)observerForInfoWithPid:(pid_t)pid; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this convenience method to create an observer that uses a delegate method instead of a callback method and includes an info dictionary to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initForInfoWithPid: for important information about creating new observer objects. See also +observerForInfoWithPath: , +observerForInfoWithURL: and +observerForInfoWithBundleIdentifier:. observerForInfoWithPid:notificationDelegate:infoCallbackSelector:Convenience class method creates and returns an initialized PFObserver object that uses a callback method that includes an info dictionary with + (nullable instancetype)observerForInfoWithPid:(pid_t)pid notificationDelegate:(nullable id)callbackDelegate infoCallbackSelector:(nullable SEL)callback; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this method to create an observer for a specific application given its BSD Unix process identification number (PID) and to set up automatic management of the observer, for an observer that uses a callback method instead of a delegate method and includes an info dictionary to respond to accessibility notifications. See the designated initializer, -initForInfoWithPid:notificationDelegate:infoCallbackSelector:, for full information about use of this method. See also +observerForInfoWithPath:notificationDelegate:infoCallbackSelector: , +observerForInfoWithURL:notificationDelegate:infoCallbackSelector: and +observerForInfoWithPid:notificationDelegate:infoCallbackSelector:. observerForInfoWithURL:Convenience class method creates and returns an initialized PFObserver object that uses a delegate method and includes an info dictionary with + (nullable instancetype)observerForInfoWithURL:(nullable NSURL *)url; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this convenience method to create an observer that uses a delegate method instead of a callback method and includes an info dictionary to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initForInfoWithPid: for important information about creating new observer objects. See also +observerForInfoWithPath: , +observerForInfoWithBundleIdentifier: and +observerForInfoWithPid:. observerForInfoWithURL:notificationDelegate:infoCallbackSelector:Convenience class method creates and returns an initialized PFObserver object that uses a callback method that includes an info dictionary with + (nullable instancetype)observerForInfoWithURL:(nullable NSURL *)url notificationDelegate:(nullable id)callbackDelegate infoCallbackSelector:(nullable SEL)callback; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this method to create an observer for a specific application given its name and to set up automatic management of the observer, for an observer that uses a callback method instead of a delegate method and includes an info dictionary to respond to accessibility notifications. See the designated initializer, -initForInfoWithPid:notificationDelegate:infoCallbackSelector:, for full information about use of this method. See also +observerForInfoWithPath:notificationDelegate:infoCallbackSelector: , +observerForInfoWithBundleIdentifier:notificationDelegate:infoCallbackSelector: and +observerForInfoWithPid:notificationDelegate:infoCallbackSelector:. observersForBundleIdentifier:Class method returns an array of observers for the running application at + (NSArray<__kindof PFObserver *> *) observersForBundleIdentifier:(NSString *)bundleIdentifier; ParametersReturn ValueAn NSArray object containing PFObserver objects. The array is empty if no observers exist for the application or the application is not running. DiscussionThis method only returns observers that were created using PFObserver factory methods. observersForPath:Class method returns an array of observers for the running application at + (NSArray<__kindof PFObserver *> *)observersForPath:(NSString *)fullPath; ParametersReturn ValueAn NSArray object containing PFObserver objects. The array is empty if no observers exist for the application or the application is not running. DiscussionThis method only returns observers that were created using PFObserver factory methods. observersForPid:Class method returns an array of observers for the running application whose BSD Unix application process identification number is + (NSArray<__kindof PFObserver *> *)observersForPid:(pid_t)pid; ParametersReturn ValueAn NSArray object containing PFObserver objects. The array is empty if no observers exist for the application or the application is not running. DiscussionThis method only returns observers that were created using PFObserver factory methods. observersForURL:Class method returns an array of observers for the running application at + (NSArray<__kindof PFObserver *> *)observersForURL:(NSURL *)url; ParametersReturn ValueAn NSArray object containing PFObserver objects. The array is empty if no observers exist for the application or the application is not running. DiscussionThis method only returns observers that were created using PFObserver factory methods. observerWithBundleIdentifier:Convenience class method creates and returns an initialized PFObserver object with + (nullable instancetype)observerWithBundleIdentifier:(nullable NSString *)bundleIdentifier; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this convenience method to create an observer that uses a delegate method instead of a callback method to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initWithPid: for important information about creating new observer objects. See also +observerWithPath: , +observerWithURL: and +observerWithPid:. observerWithBundleIdentifier:notificationDelegate:callbackSelector:Convenience class method creates and returns an initialized PFObserver object with + (nullable instancetype)observerWithBundleIdentifier:(nullable NSString *)bundleIdentifier notificationDelegate:(nullable id)callbackDelegate callbackSelector:(nullable SEL)callback; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this method to create an observer for a specific application given its name and to set up automatic management of the observer, for an observer that uses a callback method instead of a delegate method to respond to accessibility notifications. See the designated initializer, -initWithPid:notificationDelegate:callbackSelector:, for full information about use of this method. See also +observerWithPath:notificationDelegate:callbackSelector: , +observerWithURL:notificationDelegate:callbackSelector: and +observerWithPid:notificationDelegate:callbackSelector:. observerWithName:DEPRECATED. Convenience class method creates and returns an initialized PFObserver object with + (nullable instancetype)observerWithName:(nullable NSString *)name; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionThis method is deprecated. It was used to create an observer for a specific application given its name and to set up automatic management of the observer, for an observer that uses a delegate method instead of a callback method to respond to accessibility notifications. Use +observerWithPath: instead. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initWithPid: for important information about creating new observer objects. See also +observerWithPath: , +observerWithURL: , +observerWithBundleIdentifier: and +observerWithPid:. observerWithName:notificationDelegate:callbackSelector:DEPRECATED. Convenience class method creates and returns an initialized PFObserver object with + (nullable instancetype)observerWithName:(nullable NSString *)name notificationDelegate:(nullable id)callbackDelegate callbackSelector:(nullable SEL)callback; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionThis method is deprecated. It was used to create an observer for a specific application given its name and to set up automatic management of the observer, for an observer that uses a callback method instead of a delegate method to respond to accessibility notifications. Use +observerWithPath:notificationDelegate:callbackSelector: instead. See the designated initializer, -initWithPid:notificationDelegate:callbackSelector:, for full information about use of this method. See also +observerWithPath:notificationDelegate:callbackSelector: , +observerWithURL:notificationDelegate:callbackSelector: , +observerWithBundleIdentifier:notificationDelegate:callbackSelector: and +observerWithPid:notificationDelegate:callbackSelector:. observerWithPath:Convenience class method creates and returns an initialized PFObserver object with + (nullable instancetype)observerWithPath:(nullable NSString *)fullPath; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this convenience method to create an observer that uses a delegate method instead of a callback method to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initWithPid: for important information about creating new observer objects. See also +observerWithURL: , +observerWithBundleIdentifier: and +observerWithPid:. observerWithPath:notificationDelegate:callbackSelector:Convenience class method creates and returns an initialized PFObserver object with + (nullable instancetype)observerWithPath:(nullable NSString *)fullPath notificationDelegate:(nullable id)callbackDelegate callbackSelector:(nullable SEL)callback; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this method to create an observer for a specific application given its name and to set up automatic management of the observer, for an observer that uses a callback method instead of a delegate method to respond to accessibility notifications. See the designated initializer, -initWithPid:notificationDelegate:callbackSelector:, for full information about use of this method. See also +observerWithURL:notificationDelegate:callbackSelector: , +observerinitWithBundleIdentifier:notificationDelegate:callbackSelector: and +observerWithPid:notificationDelegate:callbackSelector:. observerWithPid:Convenience class method creates and returns an initialized PFObserver object with + (nullable instancetype)observerWithPid:(pid_t)pid; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this convenience method to create an observer that uses a delegate method instead of a callback method to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initWithPid: for important information about creating new observer objects. See also +observerWithPath: , +observerWithURL: and +observerWithBundleIdentifier:. observerWithPid:notificationDelegate:callbackSelector:Convenience class method creates and returns an initialized PFObserver object with + (nullable instancetype)observerWithPid:(pid_t)pid notificationDelegate:(nullable id)callbackDelegate callbackSelector:(nullable SEL)callback; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this method to create an observer for a specific application given its BSD Unix process identification number (PID) and to set up automatic management of the observer, for an observer that uses a callback method instead of a delegate method to respond to accessibility notifications. See the designated initializer, -initWithPid:notificationDelegate:callbackSelector:, for full information about use of this method. See also +observerWithPath:notificationDelegate:callbackSelector: , +observerWithURL:notificationDelegate:callbackSelector: and +observerWithPid:notificationDelegate:callbackSelector:. observerWithURL:Convenience class method creates and returns an initialized PFObserver object with + (nullable instancetype)observerWithURL:(nullable NSURL *)url; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this convenience method to create an observer that uses a delegate method instead of a callback method to respond to accessibility notifications. A client application must call -setDelegate: and -registerForNotification:fromElement:contextInfo: in order to receive notifications. See -initWithPid: for important information about creating new observer objects. See also +observerWithPath: , +observerWithBundleIdentifier: and +observerWithPid:. observerWithURL:notificationDelegate:callbackSelector:Convenience class method creates and returns an initialized PFObserver object with + (nullable instancetype)observerWithURL:(nullable NSURL *)url notificationDelegate:(nullable id)callbackDelegate callbackSelector:(nullable SEL)callback; ParametersReturn ValueAn autoreleased PFObserver object, or DiscussionUse this method to create an observer for a specific application given its name and to set up automatic management of the observer, for an observer that uses a callback method instead of a delegate method to respond to accessibility notifications. See the designated initializer, -initWithPid:notificationDelegate:callbackSelector:, for full information about use of this method. See also +observerWithPath:notificationDelegate:callbackSelector: , +observerWithBundleIdentifier:notificationDelegate:callbackSelector: and +observerWithPid:notificationDelegate:callbackSelector:. pidNumberReturns the BSD Unix process identification number (PID) of the receiver's target application. - (NSNumber *)pidNumber; Return ValueAn NSNumber object encoding an integer value. DiscussionIt is sometimes useful to know the process identification number of an application. For example, it can be used with a variety of Carbon functions to access information not otherwise readily available in Cocoa. Use NSNumber's registerForNotification:fromElement:contextInfo:Registers the receiver to observe - (BOOL)registerForNotification:(NSString *)notification fromElement:(nullable PFUIElement *)element contextInfo:(nullable void *)contextInfo; Parameters
Return Value
DiscussionUse this method to register to observe a specific UI element in a target application in order to receive notifications that it posts. Optionally pass For clients that use a delegate method, the delegate method receives the bundle identifier and full path of the target application file, the notification, the observed element, and the affected element (which may differ from the observed element). For clients that use a callback method, the callback method receives the observer, the notification, the affected element (which may differ from the observed element), and contextInfo in its parameters. Any one observer is associated with a single client delegate method or callback method no matter how many elements it is registered to observe or how many accessibility notifications it is registered to receive. A delegate method or callback method distinguishes how to respond to different notifications affecting different elements by testing its parameters. See -initWithPid:notificationDelegate:callbackSelector: for the required callback method signature for clients that use a callback method instead of a delegate method. If the client needs to remember that The client's delegate method or callback method will always receive the affected element, even when observing Many UI elements do not support every notification known to the accessibility API. If you attempt to register an element for a notification that it does not support, this method returns In Mac OS X 10.5 (Leopard), registering for either the AXApplicationActivated or AXApplicationDeactivated notification also registers for the other. The same is true of the AXApplicationHidden and AXApplicationShown notifications. The framework does this in order to work around a longstanding Accessibility API bug that Apple fixed in Mac OS X 10.6 (Snow Leopard). It is the client's responsibility to unregister an observer for all notifications before releasing it. This can be done by sending -unregisterForAllNotifications. For convenience, -removeObserversForPid: unregisters all observers for all notifications and releases all observers at once. See also -unregisterForNotification:fromElement:, -unregisterForAllNotificationsFromElement:, -unregisterForAllNotifications and -isRegisteredForNotification:fromElement:. registrationsReturns a mutable array containing all registrations currently in effect in the receiver; that is, all registrations that the client has registered and has not unregistered using this observer. - (NSMutableArray *)registrations; Return ValueAn NSMutableArray object containing all registrations currently in effect in the receiving observer. DiscussionEach registration in the array is an NSDctionary object containing the registered notification string with key "registrationNotificationKey" and the registered PFUIElement object with key "registrationElementKey". removeObserversForBundleIdentifier:Class method unregisters and removes all observers for the running application at + (void)removeObserversForBundleIdentifier:(NSString *)bundleIdentifier; ParametersDiscussionThis method only unregisters and removes observers that were created using PFObserver factory methods. See -registerForNotification:fromElement:contextInfo: for information regarding registration and unregistration. removeObserversForPath:Class method unregisters and removes all observers for the running application at + (void)removeObserversForPath:(NSString *)fullPath; ParametersDiscussionThis method only unregisters and removes observers that were created using PFObserver factory methods. See -registerForNotification:fromElement:contextInfo: for information regarding registration and unregistration. removeObserversForPid:Class method unregisters and removes all observers for the running application whose BSD Unix application process identification number is + (void)removeObserversForPid:(pid_t)pid; ParametersDiscussionThis method only unregisters and removes observers that were created using PFObserver factory methods. See -registerForNotification:fromElement:contextInfo: for information regarding registration and unregistration. removeObserversForURL:Class method unregisters and removes all observers for the running application at + (void)removeObserversForURL:(NSURL *)url; ParametersDiscussionThis method only unregisters and removes observers that were created using PFObserver factory methods. See -registerForNotification:fromElement:contextInfo: for information regarding registration and unregistration. setDelegate:Sets the receiver's delegate to - (void)setDelegate:(nullable id <PFObserverDelegate>)object; ParametersDiscussionThe delegate must adopt the PFObserverDelegate formal protocol to receive delegate messages. The PFObserver delegate methods, which are optional, are declared in the PFObserverDelegate protocol. If one of them is implemented by the delegate, it is automatically called when the receiving observer detects a change in a UI element which it has registered to observe. The delegate must adopt the PFObserverDelegate formal protocol to receive delegate messages. The only available delegate messages are -applicationWithIdentifier:atPath:didPostAccessibilityNotification:fromObservedUIElement:forAffectedUIElement: and -applicationWithIdentifier:atPath:didPostAccessibilityNotification:fromObservedUIElement:forAffectedUIElement:withInfo:, both of which are optional. The delegate is not retained. To remove a delegate, pass See also -delegate. unregisterForAllNotificationsUnregisters the receiver to observe all elements for all notifications. - (void)unregisterForAllNotifications; DiscussionIt is the client's responsibility to unregister the receiving observer for all notifications before releasing it. For convenience, -removeObserversForPid: unregisters all observers for all notifications and releases all observers at once. See also -registerForNotification:fromElement:contextInfo:, -unregisterForNotification:fromElement:, -unregisterForAllNotificationsFromElement: and -isRegisteredForNotification:fromElement:. unregisterForAllNotificationsFromElement:Unregisters the receiver to observe - (void)unregisterForAllNotificationsFromElement:(nullable PFUIElement *)element; ParametersDiscussionIt is the client's responsibility to unregister the receiving observer for all notifications before releasing it. For convenience, -removeObserversForPid: unregisters all observers for all notifications and releases all observers at once. See also -registerForNotification:fromElement:contextInfo:, -unregisterForNotification:fromElement:, -unregisterForAllNotifications and -isRegisteredForNotification:fromElement:. unregisterForNotification:fromElement:Unregisters the receiver to observe - (void)unregisterForNotification:(NSString *)notification fromElement:(nullable PFUIElement *)element; Parameters
DiscussionIt is the client's responsibility to unregister the receiving observer for all notifications before releasing it. For convenience, -removeObserversForPid: unregisters all observers for all notifications and releases all observers at once. See also -registerForNotification:fromElement:contextInfo:, -unregisterForAllNotificationsFromElement:, -unregisterForAllNotifications and -isRegisteredForNotification:fromElement:. |