Mac Developer Library

Developer

Foundation Framework Reference NSAppleEventManager Class Reference

Options
Deployment Target:

On This Page
Language:

NSAppleEventManager

Provides a mechanism for registering handler routines for specific types of Apple events and dispatching events to those handlers.

Cocoa provides built-in scriptability support that uses scriptability information supplied by an application to automatically convert Apple events into script command objects that perform the desired operation. However, some applications may want to perform more basic Apple event handling, in which an application registers handlers for the Apple events it can process, then calls on the Apple Event Manager to dispatch received Apple events to the appropriate handler. NSAppleEventManager supports these mechanisms by providing methods to register and remove handlers and to dispatch Apple events to the appropriate handler, if one exists. For related information, see How Cocoa Applications Handle Apple Events.

Each application has at most one instance of NSAppleEventManager. To obtain a reference to it, you call the class method sharedAppleEventManager, which creates the instance if it doesn’t already exist.

For information about the Apple Event Manager, see Apple Event Manager Reference and Apple Events Programming Guide.

Inheritance


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.0 and later.
  • Returns the single instance of NSAppleEventManager, creating it first if it doesn’t exist.

    Declaration

    Swift

    class func sharedAppleEventManager() -> NSAppleEventManager

    Objective-C

    + (NSAppleEventManager *)sharedAppleEventManager

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • If an Apple event handler has been registered for the event specified by eventClass and eventID, removes it.

    Declaration

    Swift

    func removeEventHandlerForEventClass(_ eventClass: AEEventClass, andEventID eventID: AEEventID)

    Objective-C

    - (void)removeEventHandlerForEventClass:(AEEventClass)eventClass andEventID:(AEEventID)eventID

    Discussion

    Otherwise does nothing.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Registers the Apple event handler specified by handler for the event specified by eventClass and eventID.

    Declaration

    Swift

    func setEventHandler(_ handler: AnyObject, andSelector handleEventSelector: Selector, forEventClass eventClass: AEEventClass, andEventID eventID: AEEventID)

    Objective-C

    - (void)setEventHandler:(id)handler andSelector:(SEL)handleEventSelector forEventClass:(AEEventClass)eventClass andEventID:(AEEventID)eventID

    Discussion

    If an event handler is already registered for the specified event class and event ID, removes it. The signature for handler should match the following:

    • - (void)handleAppleEvent:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent;

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Causes the Apple event specified by theAppleEvent to be dispatched to the appropriate Apple event handler, if one has been registered by calling setEventHandler:andSelector:forEventClass:andEventID:.

    Declaration

    Swift

    func dispatchRawAppleEvent(_ theAppleEvent: UnsafePointer<AppleEvent>, withRawReply theReply: UnsafeMutablePointer<AppleEvent>, handlerRefCon handlerRefCon: SRefCon) -> OSErr

    Objective-C

    - (OSErr)dispatchRawAppleEvent:(const AppleEvent *)theAppleEvent withRawReply:(AppleEvent *)theReply handlerRefCon:(SRefCon)handlerRefCon

    Discussion

    The theReply parameter always specifies a reply Apple event, never nil. However, the handler should not fill out the reply if the descriptor type for the reply event is typeNull, indicating the sender does not want a reply.

    The handlerRefcon parameter provides 4 bytes of data to the handler; a common use for this parameter is to pass a pointer to additional data.

    This method is primarily intended for Cocoa’s internal use. Note that dispatching an event means routing an event to an appropriate handler in the current application. You cannot use this method to send an event to other applications.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • The following constants should not be used and may eventually be removed.

    Declaration

    Swift

    let NSAppleEventTimeOutDefault: Double let NSAppleEventTimeOutNone: Double

    Objective-C

    extern const double NSAppleEventTimeOutDefault; extern const double NSAppleEventTimeOutNone;

    Constants

    • NSAppleEventTimeOutDefault

      NSAppleEventTimeOutDefault

      Specifies that an event-processing operation should continue until a timeout occurs based on a value determined by the Apple Event Manager (about 1 minute). Not currently used by applications.

      Available in OS X v10.0 and later.

    • NSAppleEventTimeOutNone

      NSAppleEventTimeOutNone

      Specifies that the application is willing to wait indefinitely for the current operation to complete. Not currently used by applications.

      Available in OS X v10.0 and later.

  • Posted by NSAppleEventManager before it first dispatches an Apple event. Your application can use this notification to avoid registering any Apple event handlers until the first time at which they may be needed. The notification object is the NSAppleEventManager. This notification does not contain a userInfo dictionary.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.