QuickLook - MacOS

QuickLook is the tool that Finder uses in MacOS to provide previews of file contents when pressing space bar on a file in Finder. qlmanage is the command line tool used to administer QuickLook.
QLManage
Use qlmanage to diagnose and change QuickLook settings.
Usage: qlmanage [OPTIONS] path...
        -h              Display this help
        -r              Force reloading Generators list
        -r cache        Reset thumbnail disk cache
        -m [name ...]   Display statistics about quicklookd. Stats names:
                        * plugins       Show the generators list
                        * server        Show quicklookd life information
                        * memory        Show quicklookd memory consumption
                        * burst         Show statistics about the last burst
                        * threads       Show concurrent accesses stats
                        * other         Show other information about quicklookd
        -p              Compute previews of the documents
        -t              Compute thumbnails of the documents
        -x              Use quicklookd (remote computation)
        -i              Compute thumbnail in icon mode
        -s size         Size for the thumbnail
        -f factor       Scale factor for the thumbnail
        -F factor       Scale factor for the thumbnail, draw downscaled and compare to 1x
        -z              Display generation performance info (don't display thumbnails)
        -o dir          Output result in dir (don't display thumbnails or previews)
        -c contentType  Force the content type used for the documents
        -g generator    Force the generator to use
To find the QuickLook generator for a specific file extension:
qlmanage -m | grep "md"
To test a quicklook generator run it explicitly on a file you want to view. For example:
qlmanage -p /path/to/sample/file.ext
Unsigned QuickLook Generators
In more recent versions of MacOS (Mohave, Big Sur, etc...) new security requirements have been put in place. This means a number of older QuickLook generators are not signed and so do not work without approval. To approve the extensions you must do the following:
- Install the QuickLook generator, e.g. brew install qlcolorcode
- On your terminal, xattr -cr ~/Library/QuickLook/QLColorCode.qlgeneratorrun (usingsudoif needed), replacingQLColorcodewith whatever the name of the QuickLook plugin
- Reload the QL Generator with qlmanage -r
- Now refresh the cache qlmanage -r cache
- Restart Finder by running killall Finder
For those wanting to cut and paste the whole lot:
brew install qlcolorcode
xattr -cr ~/Library/QuickLook/QLColorCode.qlgenerator
qlmanage -r
qlmanage -r cache
killall Finder
QuickLook Generators I use
- 
QLStephen - https://whomwah.github.io/qlstephen/ 
 This Quick Look plug-in allows you to view most text files without specific extensions (README,Makefile etc)
- 
QLColorCode - https://github.com/anthonygelibert/QLColorCode 
 Quick Look plug-in that renders source code with syntax highlighting
- 
QLMarkdown - https://github.com/toland/qlmarkdown 
 QLMarkdown is a simple QuickLook generator for Markdown files
brew install qlstephen qlcolorcode qlmarkdown
xattr -cr ~/Library/QuickLook/QLMarkdown.qlgenerator 
xattr -cr ~/Library/QuickLook/QLStephen.qlgenerator 
xattr -cr ~/Library/QuickLook/QLColorCode.qlgenerator
qlmanage -r
qlmanage -r cache
Adding support for unknown file types
If there is a file extension that is not being shown by any of your QuickLook extensions, you can easily add them to the list of one of the ones I showed above.
For example, to add .conf files to the QLColorCode extension do the following:
- 
Find an example file of the type that you want to add to QuickLook 
- 
Run mdls -name kMDItemContentTypefollowed by the file name so in my case:mdls -name kMDItemContentType /Users/me/wpa_supplicant.conf
- 
Make note of the output. In my exmaple this was: kMDItemContentType = "dyn.ah62d4rv4ge80g55sq2"
- 
Now you need to add the part in quotes to the QL config. So: nano ~/Library/QuickLook/QLColorCode.qlgenerator/Contents/Info.plistwhere QLColorCodeis the QL generator I want to add this file to.
- 
In the editor you just opened, look for three lines that look like this: </array> </dict> </array>
- 
Now add a new line before those that includes the part in quotes from step #3, so: 
 <string>dyn.ah62d4rv4ge80g55sq2</string>
- 
Press CTRL-Xand thenyandEnterto save the file
- 
Run qlmanage -r
- 
You may need to restart Finder killall Finder
Now you can press space on the new file type and it should open in QuickLook for you.
October 1, 2021 (3y ago)