"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.

Automator screenshot


After 4 years Xcode still doesn't have this feature builtin, but now it supports extensions. So here you go: "xcsort" is an extension to sort text in Xcode 8. It adds a command to sort lines in selection.