On Feb 05, 2016, at 09:24, Max Horn <[email protected] <mailto:[email protected]>>
wrote:
> 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.
______________________________________________________________________
Hey Max,
If you want to get the full text of an unsaved document you have no choice but
to use AppleScript.
If your document was always saved you can read if from disk using the
environment variable BB_DOC_PATH.
(Search for “runtime environment variables” in the user manual.)
> … 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.
You can do this in your Python script by shelling out to `osascript`:
-------------------------------------------------------------------------------------------
#! /usr/bin/env bash
read -r -d '' theAppleScript <<'EOF'
tell application "BBEdit" to tell text document 1 to return its contents
EOF
osascript -e "$theAppleScript";
-------------------------------------------------------------------------------------------
You can boil that down to this:
-------------------------------------------------------------------------------------------
#! /usr/bin/env bash
osascript -e 'tell application "BBEdit" to tell text document 1 to return its
contents';
-------------------------------------------------------------------------------------------
I prefer to use the first form, so I don't have to monkey with quoting.
It looks like there's a module for Python to run AppleScript:
http://stackoverflow.com/questions/16065162/calling-applescript-from-python-without-using-osascript-or-appscript
<http://stackoverflow.com/questions/16065162/calling-applescript-from-python-without-using-osascript-or-appscript>
> 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'd read the contents into a variable and operate on it sans file, unless the
file was quite large – or there were other advantages to having a temp file.
So. You can do what you want by including 1 line of AppleScript in your script.
--
Best Regards,
Chris
--
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].