"Sort Lines in Selection" for Xcode 4
You can do this with Automator:
- Start Automator and select either:
"Service" for macOS 10.7 or
"New Document" followed by "Quick Action" for macOS 11 - Find and drag "Run Shell Script" into the workflow panel
- Select "Output replaces selected text"
- Type
sort -f
into the "Run Shell Script" textfield - Save
Now you can sort lines in any textfield. Select some text and right-click or Control click and select the service you just created.
After 4 years Xcode still doesn't have this feature builtin, but now it supports extensions. So here you go: "xcsort" is an extension tosort text in Xcode 8. It adds a command to sort lines in selection.
How
In TextMate, open the bundle and see how they have implemented it ;)
Specifically, they have used sort -f
for that command.
In Xcode
Xc4 doesn't offer external commands, but Xc3 did... what version are you using?
Here's an overview for Xc3's script system: http://www.mactech.com/articles/mactech/Vol.23/23.01/2301XCode/index.html
Xc4 allows you to run an external script via Behaviours, but you cannot pass or return text/selection.
AppleScript
You may be able to do it with AppleScript... every time I have tried to do anything nontrivial with AS + Xcode, it didn't work out very reliably (if at all). But that was with Xc3 - locating what you need may be easier with Xc4 (unified UI and all).
I just use TextMate for this.