How do I add AppleScript support to my macOS application?
Asked on 07/30/2024
1 search
To add AppleScript support to your macOS application, you should follow these steps:
-
Adopt the
NSTextInput
Protocol: Ensure yourNSTextView
supports editing on the Mac by adopting theNSTextInput
protocol. This will allow the system to show running tools automatically in the context menu and the edit menu for custom text views. -
Implement
NSServicesMenuRequester
Protocol: Make sure your text view adopts theNSServicesMenuRequester
protocol. This protocol allows the system to read contents from the view and write contents back to the view. -
Override
validRequestor(forSendType:returnType:)
: Override this method inNSResponder
to indicate that your view can handle specific types of data. -
Add a Context Menu: Ensure that a context menu is added to the view. Once these steps are completed, the writing tools menu item will be available automatically.
For more detailed guidance, you can refer to the session "Get started with Writing Tools" at WWDC 2024.
Additionally, you might find it useful to check out the session "What’s new in AppKit" for more information on new macOS features and API refinements that could be relevant to your application.

Platforms State of the Union
Discover the newest advancements on Apple platforms.

What’s new in privacy
At Apple, we believe privacy is a fundamental human right. Learn about new and improved permission flows and other features that manage data in a privacy-preserving way, so that you can focus on creating great app experiences.

Support semantic search with Core Spotlight
Learn how to provide semantic search results in your app using Core Spotlight. Understand how to make your app’s content available in the user’s private, on-device index so people can search for items using natural language. We’ll also share how to optimize your app’s performance by scheduling indexing activities. To get the most out of this session, we recommend first checking out Core Spotlight documentation on the Apple Developer website.