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

# execute()

Executes the command if it is valid and returns the result, if any.

```
func execute() -> Any?
```

## Discussion

Before this method executes the command (through `NSInvocation` mechanisms), it evaluates all object specifiers involved in the command, validates that the receivers can actually handle the command, and verifies that the types of any arguments that were initially object specifiers are valid.

You shouldn’t have to override this method. If the command’s receivers want to handle the command themselves, this method invokes their defined handler. Otherwise, it invokes [`performDefaultImplementation()`](/documentation/Foundation/NSScriptCommand/performDefaultImplementation()).

## See Also

[`evaluatedReceivers`](/documentation/Foundation/NSScriptCommand/evaluatedReceivers)

Returns the object or objects to which the command is to be sent (called both the “receivers” or “targets” of script commands).

[`evaluatedArguments`](/documentation/Foundation/NSScriptCommand/evaluatedArguments)

Returns a dictionary containing the arguments of the command, evaluated from object specifiers to objects if necessary. The keys in the dictionary are the argument names.



---

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)