Quick Look preview from the command line

September 10th, 2008

(This post is only for Mac folks, and only the ones that spend time in the terminal at that. Everyone else can safely ignore this.)

As you may already know, you can open a file from the command line using the “open” command. The file will be opened using the default application for the file type. For example, running “open spreadsheet.xls” will open that file in Numbers or Excel, and running “open” on a directory will open that directory in a new Finder window. Think of it as a double click from the command line.

However, while working in the terminal today, I found myself wanting to open a spreadsheet using Quick Look just to get a single value. There’s a command called “qlmanage” that allows you to open the Quick Look preview of a file using the -p option. To make it more convenient, I created a short executable shell script called “ql” and put it in a directory that’s in my $PATH:


#!/bin/sh

# Display the Quick Look preview for the given file.

if [ -z "$1" ] ; then
  echo "Usage: ql ”
  exit 1
fi

exec qlmanage -p $1 2> /dev/null

Now I can preview a spreadsheet (or any file) from the command line using “ql spreadsheet.xls”. To close the preview, just hit Ctrl-C.

Leave a Reply

You must be logged in to post a comment.