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:

  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.

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.