Deversus Software Inc.

Web Developer Tip: Preview SQL Files in Mac OS Quick Look

by Mike Walsh on December 8, 2010

Mac OS X Quick Look is a great tool for being able to take a quick glance at a file’s contents, without the delays associated with launching a full app. However, there are some limitations in the file types it’s able to preview. As a web development company that deals with SQL on a daily basis, we were finally annoyed with the inability to quickly preview .sql files to the point that we decided to do a little digging.

Here’s what we came up with as a simple hack that allows you to preview .sql files with Mac OS Quick Look. This method could be used with other file types as well (e.g. .csv); you’d just need to change a couple of lines.

How We Did It

Basically, we created an empty application with a simple Info.plist file that instructs Mac OS to treat .sql file extensions as plain text.

For the impatient, you can download a zipped copy of the empty application here. Unzip and drag the application to your Applications directory and skip ahead to step 4.

UPDATE: One of our developers, Francois, wrote a quick little Spotlight importer bundle (DeversusSQLQuickLook.mdimporter) that accomplishes the same thing, without the need for an empty application. You can download the plugin here, and simply unzip and drag DeversusSQLQuickLook.mdimporter to /Library/Spotlight. You will need to restart Quick Look per step 4 below, too.

1. Launch Terminal and create the empty application in /Applications

# cd /Applications
# mkdir SQLQuickLook.app
# cd SQLQuickLook.app
# mkdir Contents
# cd Contents

2. Create a basic Info.plist file in /Applications/SQLQuickLook.app/Contents

# nano Info.plist

3. Paste the following into Info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>UTExportedTypeDeclarations</key>
	<array>
		<dict>
			<key>UTTypeConformsTo</key>
			<array>
				<string>public.plain-text</string>
			</array>
			<key>UTTypeDescription</key>
			<string>SQL File</string>
			<key>UTTypeIconFile</key>
			<string></string>
			<key>UTTypeIdentifier</key>
			<string>com.deversus.sql</string>
			<key>UTTypeTagSpecification</key>
			<dict>
				<key>com.apple.ostype</key>
				<string>sql text</string>
				<key>public.filename-extension</key>
				<array>
					<string>sql</string>
				</array>
			</dict>
		</dict>
	</array>
</dict>
</plist>

This is what tells the operating system to treat .sql files as plain text so they can be previewed via Quick Look.

To add support for more file extensions, simply modify the following section:

				<key>public.filename-extension</key>
				<array>
					<string>sql</string>
					<string>[additional_extension]</string>
				</array>

4. Save the file (Ctrl+X, Y) and restart Quick Look:

# qlmanage -r

5. You may need to restart finder for it to take effect as well

# killall Finder

That’s it. Simple and hack-ish, but hey, it works! Hopefully this helps a few other web developers out there with the same problem.

If you have any suggestions for a simpler means of accomplishing this, feel free to suggest them in the comments and I will update the post accordingly.

Leave a Comment

 

Previous post:

Next post: