Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the '10.6: Service to filter selected text using a shell command' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Service to filter selected text using a shell command
Authored by: BlackPenguin on Jun 05, '10 07:51:17AM
As MJCube noted, this will not work in BBEdit or TextWrangler, but those apps do support AppleScript and shell filters. For those who are interested, here is a quick AppleScript that will perform essentially the same task in TextWrangler that this service performs elsewhere:

tell application "TextWrangler"
	set selText to selection of window 1 as string
	set theResult to display dialog "Enter shell command to filter selected text through:" default answer "sort"
end tell

if button returned of theResult is "OK" then
	set theRes to do shell script "echo " & quoted form of selText & " | tr '\\r' '\\n' | " & text returned of theResult
end if

tell application "TextWrangler"
	set selection to theRes
end tell
This was thrown together just as a proof-of-concept, and it leaves something to be desired with respect to error checking; that's left as an exercise to the user. Hope this helps!

[ Reply to This | # ]