Quick Look — OS X service that creates thumbnails and previews for files in Finder. It supports a number of standard file types, for others there are QL plugins — custom thumbnails and preview generators. They have .qlgenerator extension and can be placed in ~/Library/QuickLook or /Library/QuickLook.
In this article, I will tell about main stages of creating custom QL plugins.
I am iOS and OSX app developer. First time I ever encountered QL plugin is when I saw Craig Hockenberry’s Provisioning preview generator for .mobileprovision files (.mobileprovision/.provisionprofile - profile containing certificates, device ids and other parameters needed for iOS & OSX app deployment).
This is how profile folder looks without any custom Quick Look plugins:
Manual profile selection may be sometimes required. In TestFlight autouploading script, for example. Choosing right profile from this pile of identical icons is quite a problem.
As a first solution, I started using the open-source Provisioning project, then closed-source (but more beautiful and detailed) ipaql. Need in own open solution arisen after the ipaql maintainer added OS X Mavericks compatibility only six months after the release and still repairing apps’ icons generation.
Here’s what I got - ProvisionQL.
Supported file types for thumbnails and previews generation:
ipa - iOS packaged application (both Xcode and AppStore supported)
app - iOS application bundle
mobileprovision - iOS provisioning profile
provisionprofile - OSX provisioning profile
And here is the result of QL plugin work:
Project settings
Create a new project in Xcode: File > New > Project… OS X > System plug-in > Quick Look Plug-in. In base template go straight to Info.plist:
Unfold CFBundleDocumentTypes and add desired file types in LSItemContentTypes array. If you want to generate small icons in lists and tables, change QLThumbnailMinimumSize from 17 to 16. Note QLPreviewHeight and QLPreviewWidth properties — they are used when generator takes too long to generate a preview. In my case – with ipa – extraction of multiple files from a zip file is required, which is quite a long task (0,06 – 0,12 s), so system always uses these plist properties. If your generator will generate a file quickly — qlmanage will use dimensions of an image or a HTML you return.
Next, if you prefer obj-c and Foundation classes — rename GenerateThumbnailForURL.c and GeneratePreviewForURL.c to GenerateThumbnailForURL.m and GeneratePreviewForURL.m and add Foundation headers there:
I need to generate both thumbnails (GenerateThumbnailForURL) and preview (GeneratePreviewForURL), so I defined common imports and functions in Shared.h/m. Here is my Shared.h:
Final ProvisionQL project structure:
NSBezierPath+IOS7RoundedRect — function for masking icon with iOS7-style rounded corners. Install.sh — autoinstall script for generator:
To run it, go to Target settings, select Editor > Add Build Phase > Add Run Script Build Phase and enter the path to the script in the project folder:
You may need to debug the plugin. Because it is not an executable itself, you must go to project scheme settings – Edit Scheme… > Run > Info > Executable > Other > press Cmd + Shft + G > /usr/bin/ > Go > qlmanage:
Then, in the Arguments tab, specify the arguments: starting with -t (for thumbnails debugging) or -p (for preview debugging), following with full path to the test file (in example case I’m testing thumbnail generation for .ipa):
Thumbnails generation
In this example I will show how to display a dummy icon (defaultIcon.png). In ProvisionQL, you can check out an implementation for ipa file extraction, as well as displaying the number of devices and the status of the provision.
This is GenerateThumbnailForURL.m:
Note some things:
you can’t use NSImage imageNamed: - this method will look for the resource in qlmanage’s (executable file) bundle, not in our plugin
check QLThumbnailRequestIsCancelled(thumbnail) before any time-consuming operation
Preview generation
In the example, we will fill and return an HTML file as a preview. First, prepare your template.html (you can also include styles there).
Everything inside the __KEY__ will be filled with the generator.
Here is our final GeneratePreviewForURL.m:
As you can see, at first we open Info.plist (or extract it from the archive if needed), then process some data from it in the synthesizedInfo. All keys of the synthesizedInfo are filled respectively in keys loaded from template.html. This string is returned to the qlmanage alongside with parameters describing the return type of the data as an HTML.
Conclusion
Following this guide, you can quickly create a plugin for quick preview and icons generating for your proprietary format or to any common format, which is not handled by the system.
Regarding ProvisionQL - I am opened to any suggestions and pull requests that can improve functionality within the plugin scope.