At 21:56 -0700 08/08/2011, Prachi Gauriar wrote:

While, John's suggestion of using a UNIX filter is a bit cleaner than
this AppleScript + Clipping stuff, the unfortunate thing about UNIX
filters is that if you don't have anything selected, it operates on
the entire text of the selection, which might not be what you want.


That's no impediment. You can simply check the length of the selection and do nothing if that is 0. Then send the command to run the filter.


set _asf to path to application support folder from user domain as string
set _tfilters to _asf & "BBEdit:Text Filters:"
set _scriptfile to "e2*.pl"
set _script to alias (_tfilters & _scriptfile)
tell application "BBEdit"
  if length of selection is 0 then return
  run unix filter {_script}
end tell

I have held for a long time that AppleScript should be used for little routines that only AppleScript can do, in this case determining whether anything is selected. When you consider the verbosity and contortions needed to work with text using BBEdit's AppleScript dictionary compared with the speed and simplicity of using Perl etc. there is simply no contest. Perl can't put up dialogues or close and measure windows and things like that, so that's where you use AppleScript. Once that is done, pick up the better tools.

All that "do shell script" stuff is a pain as well, what with the need to escape quotes etc. but where it's unavoidable the I find the following syntax the most convenient, since it removes that extra single-quoted level that you need if you do perl -e 'etc':


do shell script "perl <<END
print qq~Goodbye cruel world!~;
END"

JD

--
You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, please email "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Reply via email to