If youve ever wanted automatic code formatting in xcode like that in eclipse, it is entirely possible with an automator workflow and astyle.

first install astyle, if using macports:

sudo port install astyle


Then in our home directory we need to create a .astylerc file. This file defines the style for the code formatting. An example is provided below, for more info refer to the documentation.

Example .astylerc :

style=kr
brackets=attach
delete-empty-lines
keep-one-line-blocks
convert-tabs
indent=spaces=8
indent-namespaces
indent-classes
indent-cases
indent-preprocessor
break-blocks
align-pointer=name
suffix=nonekr


Then open up automator and create a new service. The default should be "Service recieves selected (text) in (any application)" with "Output replaces selected text" unchecked.

Check the "Output replaces selected text" checkbox. We want to replace the original text with formatted text that astyle generates. Then drag the "Run Shell Script" into the workflow area.

In the "Run Shell Script" box replace any text with:

cat <&0 > /tmp/astyle.tmp
/opt/local/bin/astyle < /tmp/astyle.tmp