---
title: "executeAppleEvent(_:error:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsapplescript/executeappleevent(_:error:)"
---

# executeAppleEvent(_:error:)

Executes an Apple event in the context of the receiver, as a means of allowing the application to invoke a handler in the script.

## Declaration

```swift
func executeAppleEvent(_ event: NSAppleEventDescriptor, error errorInfo: AutoreleasingUnsafeMutablePointer<NSDictionary?>?) -> NSAppleEventDescriptor
```

## Parameters

- `event`: The Apple event to execute.
- `errorInfo`: On return, if an error occurs, a pointer to an error information dictionary.

## Return Value

Return Value The result of executing the event, or nil if an error occurs.

## Discussion

Discussion Compiles the receiver before executing it if it is not already compiled. important: You cannot use this method to send Apple events to other applications.

## See Also

### Compiling and Executing a Script

- [compileAndReturnError(_:)](foundation/nsapplescript/compileandreturnerror(_:).md)
- [executeAndReturnError(_:)](foundation/nsapplescript/executeandreturnerror(_:).md)
