Search code examples
xcodemacossirishortcutsmacos-monterey

macOS: Intents Extension for Shortcuts opens main app and does not run for itself


I am trying to create an Intents Extension for macOS 12 Monterey.

What I've done:

  • I've created an Intents Definition file and configured a Custom Intent
  • I've created a Handler class that confirms to my Handling protocol that has been created by Xcode using the Intent Definition
  • I've added an Intents Extension as a new target that creates my Handler class in func handler(for intent: INIntent) -> Any

Problem:

My shortcut action does appear in Shortcuts. However, ever time I run a shortcut with my action, the main app launches and not the extension itself.

I've been able to figure out what I was doing wrong, look at my answer below. 👇


Solution

  • I've found two possible causes for this:

    1. Do not add your Intent to Supported Intents of your main app (info.plist) as you only have to do this if you want your main app to handle the intent via func application(_ application: NSApplication, handlerFor intent: INIntent) -> Any?. in the app delegate (a.k.a. in-app handling) - you want your extension to handle the intent
    2. By default Intent Extensions aren't sandboxed. So you have to enable App Sandbox in the build settings and add an entitlements file with com.apple.security.app-sandbox set to true. Apple should really do this for any new Intent Extension by default.
    3. When adding a new target for your Intent Extension, make sure not to select App Intent Extension. enter image description here

    Cheers!