On Jun 1, 2007, at 03:04, Walter Ian Kaye wrote:
Is the AS dictionary the same, or must scripts written for BBE be
written differently for TW? (I mean aside from the target app, of
course.)
Except for features that are available in BBEdit but not in TW, I've
had no problem using the same scripts on either application (for my
TeX integration scripts). Unfortunately I haven't found a way to
store the application is a run time variable, so the best I came up
with for producing script sets for both applications is to use a sed
script on the text version of the scripts.
When writing I use <<Editor>> in stead of "BBEdit" or "TextWrangler",
and then run
sed -e '/<<Editor>>/s//"BBEdit"/' \
< $(MASTER) > $(BBEDIT_TEXT)/$(SOURCE_BBEDIT)
or
sed -e '/<<Editor>>/s//"TextWrangler"/' \
< $(MASTER) > $(TW_TEXT)/$(SOURCE_TW)
depending on the version you're creating (actually from a Makefile.
From there you can build the scripts with the osascript command-line
compiler. I've written a little wrapper to do both a compile and a
decompile, included below. Makefiles unfortunately really do not like
spaces in file names, but I do (as those names get displayed in the
BBE or TW script menus). A wrapper script to replace _ with a space
in the filename isn't that hard to write. This scripts places the
output in the datafork, so most unix utilities can handle them
without a problem.
HTMH,
Maarten
#!/bin/bash
function my_print_help()
{
if [ -n "$1" ]
then
echo "Error: $1" > /dev/stderr
fi
cat <<EOF > /dev/stderr
Purpose: Search the tree for '*.applescript' files, optionally run
sed on them, and compile the result into a '*.scpt' file.
Usage: $0 [options]
Options:
-dest=DIR : place the compiled scripts in DIR (default: current)
-sed=STRING : run sed command STRING on the script
before compiling, original will be
left untouched.
-reverse : decompile instead of compiling (search for '.scpt',
create '.applescript'). The sed string is ignored.
EOF
if [ -n "$1" ] ; then exit 1 ; else exit 0 ; fi
}
dest="."
sedstr=""
reverse='0'
while [ $# -gt 0 ]
do
case $1 in
-dest=*) dest="${1#-dest=}" ;;
-o) shift ; dest="${1}" ;;
-sed=*) sedstr="${1#-sed=}" ;;
-s) shift ; sedstr="${1}" ;;
-r*|-dec*) reverse='1' ;;
-h|--h*) my_print_help ;;
-*) my_print_help "unrecognized option $1" ;;
--) shift; break;;
*) break;;
esac
shift
done
if [ \! -d "${dest}" ]
then
mkdir -p "${dest}"
fi
if [ "$reverse" = '1' ]
then
for ff in "$@"
do
dd="$dest/$(basename "${ff}" .scpt).applescript"
cwd="$(pwd)"
echo "Decompiling \"${ff}\" into \"${dd}\""
cat <<EOF | osascript
tell application "Script Editor"
open "${cwd}/${ff}" as POSIX file
compile document 1
save document 1 as "text" in ("${cwd}/${dd}" as POSIX file)
close document 1
end tell
EOF
done
else
for ff in "$@"
do
dd="$dest/$(basename "${ff}" .applescript).scpt"
cwd="$(pwd)"
echo "Compiling \"${ff}\" into \"${dd}\""
if [ -n "$sedstr" ]
then
sed "$sedstr" < "${ff}" | osacompile -d -t 'osas' -c
'ToyS' -o "${dd}"
else
osacompile -d -t 'osas' -c 'ToyS' -o "${dd}" "${ff}"
fi
done
fi
## end script
--
------------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_script.shtml>
List archives: <http://www.listsearch.com/bbeditscripting.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>