At 09:16 -0800 01/23/2013, Adam Engst wrote:
[...]
>What I'm trying to do is create a text _factory_ that does a few standard
>grep replacements, and then calls something else to do this renumbering
>(since there's no other way to do the renumbering from within a text
>factory that I can think of).

That's correct; there are no native actions which can directly do this.


>In the text factory, there are options for AppleScript Filter and
>Unix Filter, and I naively assumed those meant text _filters_.

They do :-) but since the terminology can get a bit convoluted, in hopes of
clearing things up a bit:

A _text filter_ is any executable code that meets the conditions given in
the manual (under "Apply Text Filter" on pg. 112), and which you can apply
to a document's contents via the Text -> Apply Text Filter submenu.

A _script_ is any executable code that you can run from BBEdit's Scripts menu.

Therefore, although a script like your original AppleScript may also be
capable of modifying text, it is not a text filter, i.e. it doesn't meet
the specific conditions needed for stand-alone use.

Beyond that:

You *can* use Unix text filters directly within a text factory, via the
'Run Unix Filter' action.

You *may* be able to use an AppleScript text filter within a text factory,
depending on how it's structured (i.e. it must contain the
"ApplyTextTransform" entry point).

In general, however, you *cannot* run Scripts menu code (either AppleScript
or Unix) within a text factory.



>So while the AppleScript I tweaked originally and Ronald's perl script
>both work, and Ronald's perl script even works from the Text Filters menu,
>neither of them can be called from within a text _factory_.

Ronald's Perl script should work when called from within a text factory if
you just edit its shebang line to use the full path to 'perl':

#!/usr/bin/perl
...

Your AppleScript, however, won't work because it requires access to a
document. (Please see my comments below regarding this.)


>So the question becomes, how would such a perl script or AppleScript need
>to be written to work from within a text _factory_?

A Unix filter (e.g. a Perl script) must accept input on STDIN and write the
modified text to STDOUT.

An AppleScript must follow the rules given in the manual (as Rich also
mentioned in his previous post):

   * When you use the Run AppleScript Filter operation, your script
     should be written with an entry point named "ApplyTextTransform".
     The input parameter to this entry point is a Unicode string
     containing the file's contents. This entry point should return
     the file's contents as a Unicode string (or something which can
     be directly coerced to one):
     ====
     on ApplyTextTransform (fileData)
         -- do something to fileData
         return fileData
         -- or some reasonable facsimile thereof
     end
     ====

It's important to keep in mind here that such an AppleScript has no
document to work with; it must instead directly manipulate the text (i.e.
the string) it receives from BBEdit.



Regards,

 Patrick Woolsey
==
Bare Bones Software, Inc.             <http://www.barebones.com/>

-- 
-- 
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>



Reply via email to