Centering things or, indeed, controlling layout outside the button order, although using toolbars is possible, is not necessarily a good idea.
Edit: I was informed that Mail.app really uses Voodoo to do something completely similar to what you offer.
They do this by tracking toolbar items and resizing the first flexible space on the toolbar to align the toolbar.
This may work for certain use cases, but is likely to be fragile; use them with caution, and keep in mind that if users can customize the toolbar, they can remove flexible space by removing centering.
source share