How to Highlight Code in Keynote

First install a utility called highlight. It is available through macports and homebrew.

sudo port install highlight

Now that highlight is installed, you can “apply” it to a file and pipe it to the clipboard:

highlight -O rtf MyCode.cpp | pbcopy

Now go to Kenote and simply paste from clipboard (or command + v). Highlight also provides a ton of syntax highlighting styles. You can see those by typing:

highlight -w

You can apply a style with the -s or --style option:

highlight -O rtf MyInput.yaml --style darkblue | pbcopy