Skip to content

Instantly share code, notes, and snippets.

@tanb
Created April 19, 2014 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanb/11094235 to your computer and use it in GitHub Desktop.
Save tanb/11094235 to your computer and use it in GitHub Desktop.
FileThumbnail
NSArray *fileURLs = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:self.url
includingPropertiesForKeys:[NSArray array]
options:0
error:nil];
[fileURLs enumerateObjectsUsingBlock:^(NSURL *fileURL , NSUInteger idx, BOOL *stop) {
NSImage *elementIcon = [[NSWorkspace sharedWorkspace] iconForFile:[fileURL path]];
CFStringRef fileExtension = (__bridge CFStringRef)[fileURL pathExtension];
CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL);
if (UTTypeConformsTo(fileUTI, kUTTypeImage)) {
// needs QuickLook.framework #import <QuickLook/QuickLook.h>
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]
forKey:(NSString *)kQLThumbnailOptionIconModeKey];
CGImageRef ref = QLThumbnailImageCreate(kCFAllocatorDefault, (__bridge CFURLRef)fileURL,
CGSizeMake(50, 50), (__bridge CFDictionaryRef)options);
elementIcon = [[NSImage alloc] initWithCGImage:ref size:CGSizeMake(50, 50)];
}
CFRelease(fileUTI);
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment