This is where I collect various useful tools that improve my efficiency in using computers. Nothing fancy.

Unix Command Line Utilities

Extract pages from a PDF file

You need Pdftk to run this command. It's a nice, lightweight, program for manipulating PDFs, and should be available in most repositories. Example: to extract pages 3-20 from a file large.pdf and create small.pdf with them, use this command:

pdftk large.pdf cat 3-20 output small.pdf

Merge PDF files

Ghostscript comes pre-installed on most Unix systems, including OS X. The following command merges file1.pdf, file2.pdf, and file3.pdf into output.pdf. You may, of course, merge more than three files by adding more arguments.

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf
file1.pdf file2.pdf file3.pdf

Split the pages of a PDF into half and recombine the split pages into a new PDF

I wrote these bash scripts so that I could read PDFs of scanned books more comfortably. These scans often have two book pages per PDF page. splits the pages down a vertical line, and splits them along a horizontal line. You must have ImageMagick installed on your system to use them. The command is

./ [number of pages in original pdf] [name of original file] [name of new pdf]

For example, if I want to convert a 13-page PDF called book.pdf into a 26-page PDF called newbook.pdf, splitting each of the 13 pages vertically down the middle, the command would be

./ 13 book.pdf newbook.pdf

(Replace "" with "" if you're splitting the pages along a horizontal line.)

A command line calculator

If you have Python installed (default in OS X), instead of using the cumbersome and slow Dashboard calculator, you can use Python's interactive mode. Type 'python' (without inverted commas) on the command line to launch it. Then you can use the usual notation to do calculations: 4*3, 6./7., etc. Note that Python returns integer values by default, so if you want an answer that isn't an integer, you need to add a '.' at the end of your input numbers (as in 6./7.) to get a floating point number back.


Write data to files with filenames indexed by some variable

This function takes in an index 'frame', a data object 'data', and writes 'data' to an output file that is named according to 'frame'. Here, the output file names will be out00.dat, out01.dat, out95.dat, etc., where the number is just the argument 'frame' in the function, but with a zero appended to the single-digit numbers. To add more padding 0s, change the %02d variable to %03d, %04d, etc.


void print(const unsigned int frame, const data_type& data) {

//create output file with filename that depends on 'frame'
   char buffer[500];
   sprintf(buffer, "out%02d.dat", frame);
   std::ofstream output(buffer);

//write data to file

//close file


Make Safari open links that are programmed to open in new windows in new tabs instead

This option isn't in Safari's Preferences. You have to change it from the command line as follows:

defaults write TargetedClicksCreateTabs -bool true