<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAppleEventManager",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAppleEventManager"
  },
  "title" : "NSAppleEventManager"
}
-->

# NSAppleEventManager

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

```
class NSAppleEventManager
```

## Overview

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](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_handle_AEs/SAppsHandleAEs.html#//apple_ref/doc/uid/20001239)

Each application has at most one instance of `NSAppleEventManager`. To obtain a reference to it, you call the class method [`shared()`](/documentation/Foundation/NSAppleEventManager/shared()), which creates the instance if it doesn’t already exist.

For information about the Apple Event Manager, see <doc://com.apple.documentation/documentation/applicationservices/apple_event_manager> and Apple Events Programming Guide.

## Topics

### Getting an event manager

[`+  sharedAppleEventManager`](/documentation/Foundation/NSAppleEventManager/shared())

Returns the single instance of `NSAppleEventManager`, creating it first if it doesn’t exist.

### Working with event handlers

[`-  removeEventHandlerForEventClass:andEventID:`](/documentation/Foundation/NSAppleEventManager/removeEventHandler(forEventClass:andEventID:))

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

[`-  setEventHandler:andSelector:forEventClass:andEventID:`](/documentation/Foundation/NSAppleEventManager/setEventHandler(_:andSelector:forEventClass:andEventID:))

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

### Working with events

[`-  dispatchRawAppleEvent:withRawReply:handlerRefCon:`](/documentation/Foundation/NSAppleEventManager/dispatchRawAppleEvent(_:withRawReply:handlerRefCon:))

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:)`](/documentation/Foundation/NSAppleEventManager/setEventHandler(_:andSelector:forEventClass:andEventID:)).

### Suspending and resuming Apple events

[`-  appleEventForSuspensionID:`](/documentation/Foundation/NSAppleEventManager/appleEvent(forSuspensionID:))

Given a nonzero `suspensionID` returned by an invocation of [`suspendCurrentAppleEvent()`](/documentation/Foundation/NSAppleEventManager/suspendCurrentAppleEvent()), returns the descriptor for the event whose handling was suspended.

[`currentAppleEvent`](/documentation/Foundation/NSAppleEventManager/currentAppleEvent)

Returns the descriptor for `currentAppleEvent` if an Apple event is being handled on the current thread.

[`currentReplyAppleEvent`](/documentation/Foundation/NSAppleEventManager/currentReplyAppleEvent)

Returns the corresponding reply event descriptor if an Apple event is being handled on the current thread.

[`-  replyAppleEventForSuspensionID:`](/documentation/Foundation/NSAppleEventManager/replyAppleEvent(forSuspensionID:))

Given a nonzero `suspensionID` returned by an invocation of [`suspendCurrentAppleEvent()`](/documentation/Foundation/NSAppleEventManager/suspendCurrentAppleEvent()), returns the corresponding reply event descriptor.

[`-  resumeWithSuspensionID:`](/documentation/Foundation/NSAppleEventManager/resume(withSuspensionID:))

Given a nonzero `suspensionID` returned by an invocation of [`suspendCurrentAppleEvent()`](/documentation/Foundation/NSAppleEventManager/suspendCurrentAppleEvent()), signal that handling of the suspended event may now continue.

[`-  setCurrentAppleEventAndReplyEventWithSuspensionID:`](/documentation/Foundation/NSAppleEventManager/setCurrentAppleEventAndReplyEventWithSuspensionID(_:))

Given a nonzero `suspensionID` returned by an invocation of [`suspendCurrentAppleEvent()`](/documentation/Foundation/NSAppleEventManager/suspendCurrentAppleEvent()), sets the values that will be returned by subsequent invocations of [`currentAppleEvent`](/documentation/Foundation/NSAppleEventManager/currentAppleEvent) and [`currentReplyAppleEvent`](/documentation/Foundation/NSAppleEventManager/currentReplyAppleEvent) to be the event whose handling was suspended and its corresponding reply event, respectively.

[`-  suspendCurrentAppleEvent`](/documentation/Foundation/NSAppleEventManager/suspendCurrentAppleEvent())

Suspends the handling of the current event and returns an ID that must be used to resume the handling of the event if an Apple event is being handled on the current thread.

[`SuspensionID`](/documentation/Foundation/NSAppleEventManager/SuspensionID)

Identifies an Apple event whose handling has been suspended. Can be used to resume handling of the Apple event.

### Constants

[NSAppleEvent Timeouts](/documentation/Foundation/nsappleevent-timeouts)

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

## Relationships

### Conforms To

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Equatable`](/documentation/Swift/Equatable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)