Hi there,
I want to write a special kind of text filter: It acts only on the current
selection, but to work, it requires the contents of the whole file. This
means that I unfortunately cannot (as far as I know) use a regular text
filter. So instead, I am trying to write an AppleScript. The idea is to
save the content of the active text document into a temporary location (to
make sure it also supports unsaved files), then call the script which
performs the actual work, passing the path to the temporary file plus
information on the current selection to that "worker script"
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.
I tried using "save text document 1 to PATH", but that is not quite what I
want -- I really want something more like "Save copy as..." or "Export
to...".
I then tried the "export" command from the BBEdit suite, but that just
gives an error, saying that text documents don't support export (BTW, is
there *any* serious documentation on the BBEdit AppleScript suite? The
BBEdit manual contains more or less zero useful information on this, as far
as I can tell).
Then I tried to write the "contents of text document 1" to a file, like
this:
on writeToFile(p, d)
try
set fd to open for access file p with write permission
set eof of fd to 0
write d to fd starting at 0 as «class utf8»
close access fd
on error
close access file p
end try
end writeToFile
tell application "BBEdit"
set fileContents to contents of text document 1
set fileName to name of text document 1
end tell
set tempFile to (path to temporary items as text) & fileName
writeToFile(tempFile, fileContents)
However, the result has LF (mac) line ends, instead of CR (unix) lineends
as the original file.
Is there any way to do this without messing up the lineends?
--
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].