Extend Xcode with customized scripts is really easy thanks to Services. WWDC 2012 session 402, Working Efficiently with Xcode, shows how to integrate a bash script in Xcode Services menu to sort and uniq headers imports in your Objective-C file.
Launch Automator, click on ’Services’, then ’Choose’:
This creates a new service that takes a text selection from any application and replaces the selection with its output.
Select ’Run Shell Script’ from the Library (you can filter actions by name, for instance ’Run’) and drag it to the right window (your service workflow):
In the shell script box, put this command:
sort -f | uniq
Select ’Output replaces selected text’ and save under the name ’Sort and Uniq’ (this will create a file called ’Sort and Uniq.workflow’ under ~/Services/). You can see that this service will receive selected text as input from any application and will replace the selection with its output.
Now, open an implementation file in Xcode, select your headers imports, right click and go to ’Services’ then ’Sort and Uniq’. Et voilà!
This service will be available on text selection from any application. This shows you how easily you can integrate custom scripts, thanks to the venerable text services of OS X.