How do I add AppleScript support to my macOS application?

Generated on 7/30/2024

1 search

Tailscan

This post is brought to you by Tailscan, the best devtool for Tailwind CSS.

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.

Platforms State of the Union

Platforms State of the Union

Discover the newest advancements on Apple platforms.

What’s new in privacy

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

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.

Get started with Writing Tools

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

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.

Bring your app’s core features to users with App Intents

Bring your app’s core features to users with App Intents

Learn the principles of the App Intents framework, like intents, entities, and queries, and how you can harness them to expose your app’s most important functionality right where people need it most. Find out how to build deep integration between your app and the many system features built on top of App Intents, including Siri, controls and widgets, Apple Pencil, Shortcuts, the Action button, and more. Get tips on how to build your App Intents integrations efficiently to create the best experiences in every surface while still sharing code and core functionality.