Code is a lot harder to read without syntax highlighting, and I needed highlighting for emails and presentations. So, I cobbled this solution from what I could find on the net. This OS X service allows me to select and highlight text in many OS X applications. It works for Pages, Keynote, and Apple’s Mail. It does not work, as written, in Microsoft Office, although you can still copy highlighted text from Pages to Word or PowerPoint, or perhaps modify this script to make it work in Office.
You will need two things to get this service working on your computer. First, download and install a command-line based syntax highlighter. Second, you need to set up an Automator workflow, to enable the service itself.
A maize maze is a tourist attraction or visitor attraction cut from a large field of living maize plants. As well as the maize maze to explore you will find other attractions such as mini-mazes, puzzles, play areas, pedal go-karts, farm animals, tractor rides, inflatable mazes and more. Maze is a Mac OS X implementation of the classic maze screen saver module seen on various platforms. It works with the Mac OS X built in screen saver.
I use highlight
. A strength of Pygments
is that it can auto-detect languages, while highlight
does not. But, Pygments
often doesn’t guess the correct language if the highlighted code is short, because today’s popular languages use highly similar syntax.
I installed highlight
using Homebrew:
To install Pygments
:
Open Applications > Automator. Choose “Service” as your new workflow type. Choose “Run Applescript” as your one and only action. Above this action, you will see some options. Set this workflow to receive text in any application. Do not check the box that says ‘Output replaces selected text’ because then this script won’t work.
In your run Applescript box, copy and paste:
I use the name “Python Syntax Highlighting” but you can call your service whatever you want. Whenever you select text in any application, your new Service will appear on the menu bar as [Application] > Services > Python Syntax Highlighting [or whatever name you saved it as]
This service works well for programs that support RTF. I use it all the time in Keynote, Pages, and Apple’s Mail. It does not work in Microsoft Office, though, although it may be possible to modify the script above to make it work in Office. Good luck!