Code examples in Keynote

Here is a quick oneliner for adding hightlighted code into the clipboard in os x:

source-highlight -d -i CodeExample.java -o STDOUT |textutil -convert rtf -stdin -stdout | pbcopy

After running the above command, you can simply paste the code into Keynote, and probably other programs as well.

This depends on source-highlight which can be installed using homebrew:

brew install source-highlight