How to display thumbnails from the Finder/QuickLook cache in my own app?

Using: macOS Sierra 10.12.6, Swift 4.0, Xcode 9.0 (Beta 6 9M214v), Storyboards

I’m trying to make a simple image viewing application for macOS. Instead of implementing my own mechanism for generating thumbnails/previews for image files on disk, it would be better if I could tap into the work already done by Finder and QuickLook, and just display thumbnails from their cache.


The API (like most of the documentation for macOS development) isn’t very clear and focuses on QuickLook Generators; whereas I just want to consume and display QuickLook/Finder thumbnail/previews.


How can I access and display the Finder-generated thumbnails for image files in my own app?

Replies

The droids you’re looking for are:

  • QLPreviewPanel, which is “a user interface object that displays the preview of a list of items”

  • QLPreviewView, which lets you embed “a Quick Look preview into your view hierarchy”

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Any way to use these classes from a sandboxed app?


My app is generating an HTML file in the Caches directory and it crashes when I try to preview it.

This thread was started in 2017. Since then, there have been a number of security updates and these caches are now considered sensitive data. I can guarantee that it won't work from the sandbox. It probably won't even work outside the sandbox in Mojave. I suggest you drop this feature.

So there is no way to use QLPreviewPanel in a sandboxed app any more? There isn't any other directory I can use for this to work?

Well, I didn't say that. I said you are not going to have direct read access, let alone write access, to the Caches directory. Quicklook still works fine in the sandbox. But you don't need to use QLPreviewPanel in a quicklook generator.


Maybe you could clarify what you are trying to do at a high level.

Sorry, let me elaborate a bit. The app is receiving assets in a packed form from the Internet. The assets can be images, text files, documents, etc. After unpacking, each asset is contained in a Data. What I would like to do is present a QuickLook view of this asset to the user.


What I tried to do was to write this Data to disk (Caches folder) and use QLPreviewPanel to show it. But I could use any other location instead if that would make a difference. I don't even need to use the filesystem, I could do it directly from memory if QuickLook supported that, but I don't think it does.


Thanks for any help