Shortcuts Action with File parameter as input conflicts with Sandbox

Hi,

I have developed a Shortcuts action for the new Shortcuts of macOS 12. I've created a custom intent and an Intents extension. My action receives one or more files as input. The file type has been set to a custom UTI com.adobe.pdf. However the files cannot be opened. I can see in the Console that Sandbox denies the access. 

If I handle the intent directly in my main app with func application(_ application: NSApplication, handlerFor intent: INIntent) -> Any? I can only open files that have been opened by the main app before. If I handle the intent in an app extension I can't open any file at all. Both the main app and the extension are sandboxed with com.apple.security.files.user-selected.read-only set to 1. My app is singed with my valid developer ID.

The example Shortcut workflow I've build simply receives PDFs as an input and is set-up to work as a Quick Action. But no matter which Shortcut configuration I choose, it does not seem to make a difference.

Interestingly everything works as expected if I set com.apple.security.files.downloads.read-write to 1. Of cause that only works with the Downloads folder.

My question: How do I have to configure my app and/or app extension in order to work with files that have been opened in Shortcuts and given to my Shortcut action as an input parameter.

Cheers and thanks for your help

Same issue here, with the exact situation (pdf), except that I'm only using the main app for now. Btw, did you manage to receive the file from the quick action input?

Hi there, yes I do receive the file from the input and I've also figured out how to access the file with the Sandbox enabled:

    func handle(intent: ExamplePDFIntent, completion: @escaping (ExamplePDFIntentResponse) -> Void) {

        if let files = intent.files,  {
            var outputFiles = [INFile]()
            for file in files {

                if file.fileURL!.startAccessingSecurityScopedResource() {
                   //do your work here
                   file.fileURL!.stopAccessingSecurityScopedResource()
                }
               else {
                   //don't forget error handling
                 }
             }
      }
}

So we have to use security scopes: https://developer.apple.com/documentation/foundation/url/1779698-startaccessingsecurityscopedreso

Makes sense now that I know it :)

Cheers

Thank you! It indeed makes sense. And you save me a headache :-).

My shortcut works, but only when selecting a PDF from the finder. If the shortcut is configured as a quick action, I can't manage to get the file. The INFile is nil. Any idea why? Thanks!

So your Shortcuts Workflow looks more or less like this?

Did you check the Privacy section?

Hi This was very helpful. I have a sandbox app and I have created a intent that need to open user-selected files and url.startAccessingSecurityScopedResource() has done the trick.

Iomegano, in your screenshot, you have the save action where you can save a content in a given file path. How did you get this action. The only action I have to save does not have "to:" argument

Regards

Vincent

Vincent, you have to uncheck "Ask Where To Save"

Shortcuts Action with File parameter as input conflicts with Sandbox
 
 
Q