My FileProviderExtension should allow creating folders in the root level, but not files. Is there a way to achieve that?
I tried creating a NSFileProviderUserInteractions
entry like
<dict>
<key>ActivationRule</key>
<string>(action == "Create" OR action == "MoveIn" OR action == "CopyIn") AND destinationItem.itemIdentifier == "NSFileProviderRootContainerItemIdentifier"</string>
<key>SubInteractions</key>
<array>
<dict>
<key>ActivationRule</key>
<string>TRUEPREDICATE</string>
<key>Alert</key>
<dict>
<key>LocalizedRecoveryOptions</key>
<dict>
<key>Cancel</key>
<string>OK</string>
</dict>
<key>LocalizedSubTitle</key>
<string>Files cannot be added to root level.</string>
<key>LocalizedTitle</key>
<string>Forbidden action</string>
<key>RecoveryOptions</key>
<dict>
<key>Continue</key>
<false/>
</dict>
</dict>
</dict>
</array>
</dict>
but this prevents creation of both files and folders in the root level. How to just prevent file creation?
Probably relevant: Apple NSFileProviderItem.h states for 'Create':
'Create': creating an item (available in macOS 12.0 and later) The Create action will be evaluated when the user creates a new file or folder in a system Open/Save panel. The sourceItem is the file/folder being created. The only field that is populated for this item is the filename. The type of file/folder, size, etc, are unknown at Create evaluation time. The destinationItem is the directory which the file/folder is being created within.
Does this mean that whether it is a file or a folder which is being created is unknown at 'Create' time? I find that quite weird and if that is the case then this cannot be supported?
The header documentation is accurate. That information is not provided in the predicate today for the Create action.
I don't think there is any way to achieve this in a blocking manner today, preventing the user from creating files (but allowing folders) at the root.
You could, in your -[NSFileProviderReplicatedExtension createItemBasedOnTemplate:]
implementation, decide to return a different parentItemIdentifier
property on the NSFileProviderItem
in the completion handler. That will cause the system to move the item on disk to the new parent.
You could notify the user that they performed an invalid operation, and that your application moved the file somewhere else.