2

Is there a way in OS X to find out if QuickLook can (potentially) preview a file, given just its name?

My specific case is I'm showing previews for files in a git repository, so they have to be extracted in order to give them to QuickLook. I'd rather avoid that work if there's no chance a preview will actually be displayed.

I saw that in iOS you can do [QLPreviewController canPreviewItem:], but that's not available on OS X.

Uncommon
  • 3,323
  • 2
  • 18
  • 36

2 Answers2

1

After checking QLPreviewView for blank previews, found it sets few variables like "contentImage : NSImage " ,"numberOfPages : Int", "isLoaded : Bool" once its drawn and visible on the view.

If preview is not supported the contentImage will be set with the placeholderImage and numberOfPages will be 0 , it will be viceversa otherwise.

If someone doesn't want to check for the supported FileTypes, they can look for these variables using value(forKey : ) method, as these variables are not exposed publicly.

Kirty07
  • 53
  • 4
  • But that would be after you try to display the preview, right? I want to know in advance so I can avoid a potentially expensive operation. – Uncommon Jun 07 '19 at 17:41
  • Yes it will be after we let previewItem to display. If we have to do that in advance, we need to check for the file extensions only, until Apple release some api specific to this scenario. – Kirty07 Jun 11 '19 at 08:57
  • @Uncommon how you got around this case? Do you check for filetypes before loading in the preview view, if yes, can you please share me the list of unsupported/supported file extensions in QLPreview View. – Kirty07 Jun 12 '19 at 06:21
  • I haven't found the answer yet. – Uncommon Jun 12 '19 at 12:23
0

You may wish to peruse the Apple Developer documentation regarding Quicklook:

https://developer.apple.com/library/archive/navigation/#section=Technologies&topic=QuickLook

In there they mention there are three locations which contain the preferences for Quicklook, you may want to have a poke around these:

~/Library/QuickLook — third party generators, accessible only to logged-in user
/Library/QuickLook — third party generators, accessible to all users of the system
/System/Library/QuickLook — Apple-provided generators, accessible to all users of the system

I have managed to modify Quicklook to view differing files as plain text (mine were .crd files, which are music tabs), but I can't find the site that walked me through that. I'll post the instructions if I can find them again.

HTH!!

neophytte
  • 648
  • 2
  • 11
  • 25