The UNIX shell provides a host of extremely useful utilities for modifying text. This OS X Automator service makes all of them available for filtering text in all OS X applications.
This can be handy for performing quick operations, like replacing text with regular expressions, sorting lists or swapping fields around.
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}'
![]()
Put it in Library/Services, and it should appear in the ‘Services’ menu.
Filter through Shell Command.zip
Related posts
- A OS X service to encode HTML characters I find myself frequently writing HTML code in comment forms...
- Convert text to iTunes audio book After reading a hint on macosxhints on how to create...
- A brief shell scripting tutorial Shell scripts are very useful things, whether they’re prepared and...
- Unix tools tutorial Last week we took a quick look at shell scripting....
- DIY Twitter image hosting Twitter doesn’t yet come with its own inline image support,...
10 Comments
Hi,
Any chance we could get GUI for commands in future? :-) There is not so many comand line friens as mose clickers :-)
Hi Frantisek,
Actually, this is more targeted for the command line-fiends ;-)
There appear to be a few products out there that are more targeted for normal users – A quick glance reveals two possibilities (I haven’t tried them): Text Wielder and maybe TextExtras.
Cheers!
i give up, can you make me one that do not ask for input but just runs “sed ‘s/\./ /g;s/\-/ /g;s/\_/ /g’” thanks in advance
Hi Nikola,
You can make that change pretty easily – if you double-click the workflow, it’ll open up in Automator; then you can replace all the text in the “Run Shell Script” panel with just your command (“sed ….”). Then save, and you’re done.
thanks i tyred modifying yours (replacing sort etc) but it never worked.. it never occurred to me to replace all text, guess i’ll never understand applescript :)
I installed ‘Filter Through Shell Command’ in my user Library/Services, not the root Library/Services on my Mac OS X 10.6.3, but I do not see the ‘Filter Through Shell Command’. Does this run on OS X 10.6.3? What am I doing wrong?
Thank you.
Hi Ron,
That should do it – have you tried rebooting or logging out and back in again? There’s a chance you may also need to specifically enable it in Keyboard Preferences (in System Prefs)
I did reboot and ‘Filter through Shell Command’ is checked under ‘text’ in Keyboard preferences and I still do not see the command when I go to Services.
What app are you trying to use it from? I’ve noticed some apps are a little dumb in the way they report the data type to the Services menu provider. For example, if I select the text I’m currently typing in Chromium, nothing comes up in Services at all. Try TextEdit (copying and pasting into it, if need be)
That works.
Thanks.
One Trackback
[...] 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 [...]