<!--
{
  "documentType" : "article",
  "framework" : "FileProviderUI",
  "identifier" : "/documentation/FileProviderUI/adding-actions-to-the-context-menu",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Adding Actions to the Context Menu"
}
-->

# Adding Actions to the Context Menu

Present custom actions from your File Provider extension in the system’s file browser.

## Overview

In your File Provider UI extension’s `Info.plist` file, you can define custom actions that appear in the context menu when the user long-presses an item while browsing your file provider’s content. When the user selects the action, the system presents a custom user interface element from your File Provider UI extension.

In macOS 11 and later, you can define custom actions directly in the File Provider extension. The system also adds these actions to the context menu; however, when the user selects them, your extension performs the action without presenting any additional UI elements. For more information, see <doc://com.apple.documentation/documentation/FileProvider/NSFileProviderCustomAction>.

### Add Actions to the Context Menu

Add an `NSExtensionFileProviderActions` key to the `NSExtension` dictionary in your `Info.plist` file, as shown in the example below.

```xml
<key>NSExtensionFileProviderActions</key>
<array>
	<dict>
		<key>NSExtensionFileProviderActionIdentifier</key>
		<string>com.example.MyFileProvider.setRating</string>
		<key>NSExtensionFileProviderActionName</key>
		<string>Rate</string>
		<key>NSExtensionFileProviderActionActivationRule</key>
		<string>SUBQUERY( fileproviderItems, $fileproviderItem, $fileproviderItem.userInfo.rank != nil ).@count > 0</string>
	</dict>
</array>
```

The `NSExtensionFileProviderActions` key takes an array of dictionaries. Each dictionary represents a single action, and contains the keys shown in this table.

|Key                                          |Type                  |Description                                                                |
|---------------------------------------------|----------------------|---------------------------------------------------------------------------|
|`NSExtensionFileProviderActionIdentifier`    |`String`              |A unique identifier for the action.                                        |
|`NSExtensionFileProviderActionName`          |`String` (Localizable)|The localized name that appears in the context menu.                       |
|`NSExtensionFileProviderActionActivationRule`|`Predicate`           |A predicate that determines whether the action appears in the context menu.|

The following sequence of events occurs when the user selects one of your actions from the context menu:

1. The system instantiates your [`FPUIActionExtensionViewController`](/documentation/FileProviderUI/FPUIActionExtensionViewController) subclass.
2. The system calls your view controller’s [`prepare(forAction:itemIdentifiers:)`](/documentation/FileProviderUI/FPUIActionExtensionViewController/prepare(forAction:itemIdentifiers:)) method. You can override this method to configure the user interface for the selected action.
3. The system presents your view controller to the user.
4. After the user has finished performing the action, you call the provided [`FPUIActionExtensionContext`](/documentation/FileProviderUI/FPUIActionExtensionContext) object’s [`cancelRequest(withError:)`](/documentation/FileProviderUI/FPUIActionExtensionContext/cancelRequest(withError:)) or [`completeRequest()`](/documentation/FileProviderUI/FPUIActionExtensionContext/completeRequest()) method to complete the action.

### Use Predicates to Enable and Disable Actions

Use the `NSExtensionFileProviderActionActivationRule` key to enable or disable actions based on the selected file provider item. Set the key’s value to a predicate format string that the system uses to create an <doc://com.apple.documentation/documentation/Foundation/NSPredicate> object. The system calls the predicate’s <doc://com.apple.documentation/documentation/Foundation/NSPredicate/evaluate(with:)> method, passing in the selected item, a dictionary with a single `fileproviderItems` key. The value is an array of <doc://com.apple.documentation/documentation/FileProvider/NSFileProviderItem-swift.typealias> objects representing the selected items.

> Important: Your action must have a predicate or the system won’t display it in the action menu. To always show an action, use `TRUEPREDICATE`.

You can use predicates to test the value of any of the <doc://com.apple.documentation/documentation/FileProvider/NSFileProviderItemProtocol> object’s properties. For example, the following predicate tests whether the <doc://com.apple.documentation/documentation/FileProvider/NSFileProviderItemProtocol/isUploaded> property is set to <doc://com.apple.documentation/documentation/Swift/true>.

```other
SUBQUERY ( fileproviderItems, $fileproviderItem, $fileproviderItem.uploadded == YES ).@count > 0
```

You can also use predicates to test custom data that you’ve added to the item’s <doc://com.apple.documentation/documentation/FileProvider/NSFileProviderItemProtocol/userInfo> dictionary. For example, the following predicate tests whether the `com.example.testBit` key has been set.

```other
SUBQUERY( fileproviderItems, $fileproviderItem, $fileproviderItem.userInfo."com.example.testBit" == YES ).@count > 0
```

If a predicate evaluates to <doc://com.apple.documentation/documentation/Swift/true>, the context menu includes the action; if <doc://com.apple.documentation/documentation/Swift/false>, the context menu doesn’t include the action. For more about creating predicate format strings, see [Predicate Format String Syntax](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html#//apple_ref/doc/uid/TP40001795).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)