Read files from Pasteboard file-url inside macOS sandbox

214 views Asked by At

I would like to show a preview of the file contained in the pasteboard inside my sandboxed app. I'm able to do this using the QuickLookThumbnailing package.

Unfortunately, this requires a read access and does not work for files that are not inside the basics folders, such as Download, Video, Photo and Music. For other cases I will get the error couldn't issue sandbox extension com.apple.app-sandbox.read for '<path to file>'

I understood that in the sandbox design, file's access are supposed to be approve from the user somehow. But in other application (sandboxed too), I can paste a file without being prompted for any confirmation.

How do they do this ?

Finder never provide a Security-Scoped Bookmark inside the pasteboard.

2

There are 2 answers

0
mahal tertin On

You don't get a security scoped bookmark but a path/URL that has read/write rights granted. You then create a security scoped bookmark and store it for subsequent access. This works for the general pasteboard (copy-paste) as well as for the drag clipboard.

0
defcc On

As for sandbox env, when read from pasteboard, you have access to the file temporarily. But you just get one chance. That's said, you could not call pasteboard.readObjects or other apis more than once.

You could paste you code here and provide more information.