How do I add AppleScript support to my application on macOS?
Asked on 07/30/2024
1 search
To add AppleScript support to your application on macOS, you can 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.
Relevant Sessions
These sessions provide insights into integrating writing tools and other features into your macOS applications.

Get started with Writing Tools
Learn how Writing Tools help users proofread, rewrite, and transform text in your app. Get the details on how Writing Tools interact with your app so users can refine what they have written in any text view. Understand how text is retrieved and processed, and how to support Writing Tools in custom text views.

What’s new in AppKit
Discover the latest advances in Mac app development. Get an overview of the new features in macOS Sequoia, and how to adopt them in your app. Explore new ways to integrate your existing code with SwiftUI. Learn about the improvements made to numerous AppKit controls, like toolbars, menus, text input, and more.

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.