Suppose I have some selected text in Messages or Notes or something, and I'd like to sort the lines. Right now, I don't think there's really a good way to do it...
Is there a way with KM to have it pop up a dialog and ask for a unix command, e.g. "sort | uniq", and then copy the text, push it through those unix commands as STDIN, then paste the STDOUT from that command back in over the selected text? Obviously it'd lose its formatting, but that's fine.
On the contrary, I think there is a good way to do this. KM comes with a macro called "Activate Clipboard History Switcher" which is triggered by SHIFT-CTRL-CMD-V by default. It will activate the clipboard history window. So prior to launching it, copy the text from Messages or Notes into your system clipboard. Then activate the macro. Then click on the cogwheel for the clipboard at the top of the wheel. You will see a list of filters in the menu that pops up. None of those menu items is sort, but you can easily create one by adding this macro into the Clipboard Filters folder:
Then I think you also have to press the CMD-V in your app to replace the selected text with the new, sorted text.
There might even be a way to automate the Copy and Paste with the filter, but I need more time to think about that.
I haven't figured out if there's a way to let the user type the filter manually, as you preferred, but as far as your original problem of sorting selected text, this gets pretty close to what you want.
Warning: this executes the shell command of whatever you type in the prompt, so you really need to be as careful with what you type as you would be with anything you typed in the Terminal.
Note that this saves the text you type to a file because that is the easiest way to execute a variable as a script.
KM has a "sort" Filter action, but it doesn't have a "unique" built in -- you could roll one yourself by sorting then "For Each"ing through the lines and comparing each to the previous one.
But if you are happy to lose formatting, the "Execute a Shell Script" action makes it easier. Why do you want to have to enter the command in a prompt, though (see also Peter's warning about being very careful what you type)?
If you do want to simply Copy, sort | uniq, and Paste the result it should be as simple as:
I just played around with it for awhile and it's basically perfect, lets me filter, awk, sort, word count, python script/filter, etc., anything that I have selected in Notes, Messages, etc. It's awesome.