Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpcweb/aac426e983879e33a19ffbfbb8107fbe to your computer and use it in GitHub Desktop.
Save jpcweb/aac426e983879e33a19ffbfbb8107fbe to your computer and use it in GitHub Desktop.
Github style syntax highlighting in Pages.app

I like Pages.app, but don't want to deal with constantly copying and pasting code around.

Here is how I do syntax highlighting in Pages.app by pressing a key command. It's based off of this post on stack exchange.

install pygments

sudo easy_install Pygments

install github syntax

git clone git://github.com/hugomaiavieira/pygments-style-github.git
cd pygments-style-github
python setup.py install
pygmentize -L styles | grep github # should now be listed

Open "Applescript Editor.app" and turn on the script menubar in preferences

Save this script.

Adjust pygmentize command if you want to use a specific language, use lang autodetect, etc...

try
  set old to the clipboard as record
end try

tell application "System Events" to keystroke "c" using command down
do shell script "export LC_CTYPE=UTF-8; pbpaste | /usr/local/bin/pygmentize -g -l ruby -f rtf -O style=github | pbcopy"
tell application "System Events" to keystroke "v" using command down
delay 0.1

try
  set the clipboard to old
end try

put the script where it belongs

  1. Open pages

  2. Go to our newly added script icon in menu bar and select "Open Scripts Folder > Open Pages Scripts Folder"

  3. Move the script you just saved to that folder.

Script now available from the menue while in pages. Select text, then chose the script from the menu.

Setup the key command

If you want the script triggered on a key command, as I did, install Fastscripts — you'll get 10 free keyboard shortcuts to applescripts (you could also use Automator and setup a service)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment