10.6: Service to filter selected text using a shell command
May 24, '10 07:30:00AM • Contributed by: michaeltyson
May 24, '10 07:30:00AM • Contributed by: michaeltyson
Here's a little OS X service to filter selected text (from any application) through a shell command.
This can be handy for performing quick operations, like replacing text with regular expressions, sorting lists or swapping fields around.
Grab the Filter through Shell Command service, extract the zip file and put the service into /Library/Services. You may need to authenticate to do this. It should then appear in the Services menu.
When triggered, the service requests a command to use for filtering, then runs the command and replaces the selected text with the result.
Some sample operations:
- Sort lines alphabetically/numerically: sort or sort -n
- Change to lowercase: tr "[:upper:]" "[:lower:]"
- Replace a spelling mistake, taking care of case: sed -E 's/([tT])eh/\1he/g'
- Re-order elements in a tab- or comma-separated list: awk '{print $2 $1}' or awk -F, '{print $2 "," $1}'
[crarko adds: I tested this, and it works as described in TextEdit. BBEdit did not accept the command for me.]
•
[6,557 views]
