On Mon, 21 Mar 2011 08:27:45 -0400, Rich Siegel wrote:
On Monday, March 21, 2011, Charlie Garrison <[email protected]> wrote:

FRONT_DOC=`osascript -e 'tell application "BBEdit" to get POSIX path of ((file of front document) as string)'`

So, not built-in to BBEdit, but just a one-liner to add to existing scripts.

When you run a script or filter from the #! menu, BBEdit sets up some
variables in the environment, one of which is BB_DOC_PATH, the path to
the front document. (This was introduced in 9.3, so you can find more
details in the 9.3 change notes at
<http://www.barebones.com/support/bbedit/arch_bbedit93.html>, as well
as in the user manual.)

If you're running a script outside of BBEdit, then the example above
is definitely useful and helpful.

What's more, the above will probably not return if called in a script which is invoked from the #! menu. BBEdit does not process AppleEvents while running #! scripts - this includes using appscript from python or ruby.

if [ -z "$BB_DOC_PATH' ]
then
FRONT_DOC=$(osascript -e 'tell application "BBEdit" to get POSIX path of ((file of front document) as string)')
else
    FRONT_DOC=$BB_DOC_PATH
fi

(and yes, there are more fancy methods with {}?!- and other characters thrown in for good measure. This is somewhat readable ;-)

Maarten

--
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