Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Sort Lines in Selection" for Xcode 4

I like Textmate's "Sort Lines in Selection" feature a lot. Is there something similar for Xcode 4? If not, what would be the best way to integrate such a feature (a plugin, Applescript, ...)?

like image 449
Lars Schneider Avatar asked Nov 12 '11 10:11

Lars Schneider


3 Answers

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

like image 133
epatel Avatar answered Oct 04 '22 12:10

epatel


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.

like image 2
battlmonstr Avatar answered Oct 04 '22 13:10

battlmonstr


For macOS 10.14+ (Mojave) users who are looking at epatel's answer, Automator has renamed Services to Quick Action. I was lost for a moment until I figured it out.

like image 2
Haoxin Li Avatar answered Oct 04 '22 11:10

Haoxin Li