Shell commands are normally needed when someone wants to process text/text files to convert all uppercase letters to lowercase letters or deletion of entire class of characters. Despite of the fact, that you can download the new scripts for editing text files in Mac, some users like to do things on their own. Hence, take a look at the whole process…

Mac OSX Mockup Wallpaper - Google Images

Open the Automator and select “Service” from the opened window. Now you can drag the “Run Shell Script” from the Utilities panel and paste the following script, into your open script window;

result=`osascript -e ‘tell application “System Events”‘ -e ‘activate’ -e ‘set result to (display dialog “Enter shell command to filter selected text through:” with title “Filter text” default answer “sort” buttons {“Cancel”, “Filter”} default button 2)’ -e ‘text returned of result & “%%SEP%%” & button returned of result’ -e ‘end tell’ | sed ‘s/”/\”/g’`

[ ! “$result” ] && cat && exit;

button=`echo “$result” | sed s/.*%%SEP%%//`

command=`echo “$result” | sed s/%%SEP%%.*//`

[ “$button” = ‘Cancel’ ] && cat && exit;

cat | sh -c “$command”

after you are done with it, you can save the changes and go for any name, but make sure that you set the save location to Library/Services. But those users who think the process is “too complicated”, they can just download a zip version of that script and save it at the same location, that I mentioned above.

Afterwards, select your workflow and you will see a new pop up window, which is your Filter Text dialogue box. Here you can enter any shell command that you want to use and then click on “Filter”. As a result, your command will be processed and applied to the selected text and feel free to make changes of your own, as there are no limitations to this script.