Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access QuickLook plugin resources?

My QuickLook plugin generates HMTL preview for the document. I need to display images saved in the plugin bundle. Simply using imageNamed: method to get an instance of the NSImage class doesn't work. How can achieve that? Is that a consequence of the fact that

Quick Look generators are designed as CFPlugIn-style bundles.

as the documentation says?

like image 538
dzolanta Avatar asked Nov 27 '10 14:11

dzolanta


People also ask

Where are QuickLook plugins stored?

QuickLook looks for and uses the plugins from both system-wide folders '/System/Library/QuickLook' and '/Library/QuickLook' and also the home folder of each user in '~/Library/QuickLook'. A QuickLook plugin is organised in a folder with an extension .

How do I use QuickLook on Windows?

Click any file, and hit the spacebar. You'll instantly see a preview of it. You can use the arrow keys to jump between files—the preview will immediately load. Here are the file types you can see with QuickLook.

How do I install QuickLook plugins?

To install QuickLook plugins, you should copy the “*. qlgenerator” file into /Library/QuickLook/ or ~/Library/QuickLook/. Note that “*” in the filename will vary based on exactly which QuickLook item you choose to install. If a QuickLook folder is not present, feel free to create one.

What is QuickLook on my Iphone?

Quick Look offers a fast, full-size preview of nearly any kind of file without opening the file. You can rotate photos, trim audio and video clips, and use Markup—directly in the Quick Look window.


2 Answers

I believe +imageNamed: uses the +mainBundle method of NSBundle. In that case, that's not your plugin's bundle.

I think you'll need to ask the plugin's bundle directly:

NSString * path = [[[NSBundle bundleForClass:[MyPluginClass class]] pathForResource:@"MyImage" ofType:@"tif"];
NSImage * image = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];

This was written in the browser, so it may not be exact. :-)

like image 121
Joshua Nozzi Avatar answered Oct 21 '22 21:10

Joshua Nozzi


Within the plug-in code, you can access your plug-in CFBundle:

QLThumbnailRequestGetGeneratorBundle or QLPreviewRequestGetGeneratorBundle

Once you have the bundle, you can query for resources file URLs using:

CFBundleCopyResourceURL

like image 34
Julien Avatar answered Oct 21 '22 19:10

Julien