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:

  1. Adopt the NSTextInput Protocol: Ensure your NSTextView supports editing on the Mac by adopting the NSTextInput protocol. This will allow the system to show running tools automatically in the context menu and the edit menu for custom text views.

  2. Implement NSServicesMenuRequester Protocol: Make sure your text view adopts the NSServicesMenuRequester protocol. This protocol allows the system to read contents from the view and write contents back to the view.

  3. Override validRequestor(forSendType:returnType:): Override this method in NSResponder to indicate that your view can handle specific types of data.

  4. 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.