I should change that variable htmlTitle back to fileData. Even though I 
don't actually use it, it is misleading.

On Friday, November 10, 2023 at 8:30:00 AM UTC-5 Eros9 wrote:

> Hi, PDeL -- My script returns "some reasonable facsimile thereof". I just 
> skipped defining the variable "fileData" (or "htmlTitle" in my script) and 
> returned the string itself. It might be confusing that the string includes 
> line breaks, which the script editor actually displays as such; the string 
> is bound by the parentheses. The main breakthrough in my grasping how the 
> script works in the context of a text factory is that whatever it returns 
> completely replaces the contents of the file being acted on, so the script 
> has to read all the contents first, do its thing, and return them back. In 
> my case, that was just adding an html title header with the file name. I 
> hope I've been helpful!
>
> On Thursday, November 9, 2023 at 8:28:08 PM UTC-5 PDeL wrote:
>
>> Hi Eros9. This is indeed very interesting, and potentially very helpful 
>> for a different thing I'm trying to do.
>> But I don't understand HOW you run the AppleScript in the context of a 
>> Text Factory. In the user guide the only mention I see of AS in relation to 
>> a TF is the "Run AppleScript Filter" option,  which is documented as shown 
>> below. I'm kind of thrown off by the statement "This entry point should 
>> return the file’s contents as a Unicode string." Is this what you're 
>> using?
>>
>> 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
>>
>> On Thursday, November 2, 2023 at 10:30:49 AM UTC-7 Eros9 wrote:
>>
>> This may be helpful to somebody. I have a text factory that is a chain of 
>> "Replace All" commands to create an html proof of an xml file. I wanted to 
>> add the file name to the proof, because it is crucial for correct 
>> processing of the xml (when it's uploaded to the system in question). 
>> Here's the Applescript, which is run at the start of the text factory:
>>
>> on ApplyTextTransform(htmlTitle)
>> tell application "BBEdit"
>> activate
>> set fileName to (name of document 1) as text
>> set fileCont to (contents of document 1) as text
>> return ("<html>
>> <head>
>> <title>" & fileName & "</title>
>> </head>
>> " & fileCont)
>> end tell
>> end ApplyTextTransform
>>
>> Then a grep replace command in the text factory finds the fileName and 
>> adds it as part of the html body as well. (I realize that the htmlTitle 
>> variable in the script is superfluous.)
>>
>>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "supp...@barebones.com" rather than 
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/fc93f539-96a3-4640-ab35-754966bd189fn%40googlegroups.com.

Reply via email to