Hi Christopher, thank you for your help.
Am Donnerstag, 4. Februar 2016 11:56:38 UTC+1 schrieb Christopher Stone: > > On Feb 03, 2016, at 11:28, Max Horn <[email protected]> wrote: > > it requires the contents of the whole file. This means that I > unfortunately cannot (as far as I know) use a regular text filter. > > ______________________________________________________________________ > > Hey Max, > > You probably can use a regular text filter by putting your get-text > AppleScript in with `osascript`. > Note sure what you mean with that. Perhaps this is a misunderstanding? To clarify, I would prefer *not* to use AppleScript, almost any other language is preferable to me. The reason I am not using a regular text filter is that to my understanding, a (non-AppleScript) text filter receives *only* the content of the current selection (if there is any), or else receives the whole text file, in either case on stdin. That doesn't work for me, though: While the text transformation I have implented is transforms only the currently selected text, to work correctly it *needs* to know the complete content of the file to work correctly. If doing that is possible with a text filter in a way that does not require me to write any AppleScript, I'd love to know that. > The idea is to save the content of the active text document into a > temporary location (to make sure it also supports unsaved files) > > > That doesn't make obvious sense, unless you're wanting to save so you can > read it back from disk. > I want to store the content to a temporary file, so that my actual filter tool (written in Python, and invoking various command line tools) can process the full content of the file -- I can pipe the content of the temp file into the tool, and pass the selection start and length as command line parameters to the tool (and if there is no selection, I signal that by not passing in any command line parameters). So, of course I want to read the file back from disk, I just don't want to do it from AppleScript, nor from BBEdit. I only use AppleScript as that seems to be the only chance of doing what I need -- but again, I'd love to learn of alternatives, if there are any. [...] > To my surprise, the hardest part seems to be to actually store a copy of > the contents of the text document into a temporary file... All my attempts > so far failed. > > > Simple. ( When you know AppleScript and have spent many hours scripting > BBEdit. :) > > > ------------------------------------------------------------------------------------------- > *tell* *application* "BBEdit" > *tell* *front* *text document* > *set* docName *to* *its* name > *set* _text *to* *its* *text* > *end* *tell* > *set* tempFilePath *to* (*path to* *temporary items* as *text*) & > docName > *set* newDoc *to* *make* new *document* with properties {*text*:_text} > initial > save location tempFilePath > *save* newDoc > *end* *tell* > > ------------------------------------------------------------------------------------------- > That's educational, thank you -- the content of the temp file it generates is perfect, alas even adding a "close newDoc" in, one briefly sees a new window flash up in BBEdit, which is undesirable. Still, good to learn about this approach. [...] > I work around that in the script with this line: > > # Convert carriage returns to linefeeds. > *set* _text *to* *replace* "\\x{0D}" using "\\x{0A}" searchingString _text > options {search mode:*grep*, case > > So. That should give you some ideas > Yes, thank you. However, the key result seem to be this: "It is not really possible to do this, but you can workaround the line ends problem by converting them manually" -- which of course I already could do by adding a conversion step to my python script. I just thought it was natural for the scripting interface of a text editor to allow a verbatim export of the content of a text document to a temp file, and that I must be missing something for not finding it. Seems I didn't really miss anything :) Anyway, so knowing that, I'll just accept that I have to do a line ends conversion, no biggie. Cheers, Max -- This is the BBEdit Talk public discussion group. 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> --- 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 [email protected]. To post to this group, send email to [email protected].
