Skip to content

Instantly share code, notes, and snippets.

@Joilence
Forked from sudara/Github-style-syntax-in-pages.md
Last active November 12, 2020 10:01
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 Joilence/2f8bfc29d813d1066df4a0bcd0acc5f6 to your computer and use it in GitHub Desktop.
Save Joilence/2f8bfc29d813d1066df4a0bcd0acc5f6 to your computer and use it in GitHub Desktop.
Github Style Code Syntax Highlighting in Pages.app

Based on this post on stack exchange.

install

# install Pygments
sudo easy_install Pygments # or brew install pygments

# install gihub style 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 "Script Editor.app" and turn on the script menu bar in preferences

Create 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 file to Pages.app

  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 to the Pages folder.

Script now is available from the Script Menu while Pages.app is activated. 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