Hi Tim,
BBEdit offers plenty of options to manipulate text:
• Scripting with Script Editor or Script Debugger using BBEdit's rich
vocabulary of objects and commands:
◦ AppleScript, AppleScriptObjc, JavaScript
• Any executable that can read BBEdit's environment variables:
◦ Interpreted languages: python, perl, javascript, ruby, php, etc;
◦ Shell scripts and command line utilities;
◦ Custom compiled executables.
Which is better depends on the task at hand and your coding preferences.
Here is a sample shell script that reads the environment variables BBEdit's
sets up:
#!/usr/bin/env sh
# Name of the document's current language (not set if language is
"none")
echo BB_DOC_LANGUAGE $BB_DOC_LANGUAGE ;
# Emacs mode of the document's current language
echo BB_DOC_MODE $BB_DOC_MODE ;
# name of the document
echo BB_DOC_NAME $BB_DOC_NAME ;
# path of the document (not set if doc is unsaved)
echo BB_DOC_PATH "\"$BB_DOC_PATH\"" ;
# (zero-based) end of the selection range (not set if not text document)
echo BB_DOC_SELEND $BB_DOC_SELEND ;
# (one-based) de-tabbed column number of BB_DOC_SELEND
echo BB_DOC_SELEND_COLUMN $BB_DOC_SELEND_COLUMN ;
# (one-based) line number of BB_DOC_SELEND
echo BB_DOC_SELEND_LINE $BB_DOC_SELEND_LINE ;
# (zero-based) start of the selection range (not set if not text
document)
echo BB_DOC_SELSTART $BB_DOC_SELSTART ;
# (one-based) de-tabbed column number of BB_DOC_SELSTART
echo BB_DOC_SELSTART_COLUMN $BB_DOC_SELSTART_COLUMN ;
# (one-based) line number of BB_DOC_SELSTART
echo BB_DOC_SELSTART_LINE $BB_DOC_SELSTART_LINE;
# length of the selection
SEL_LENGTH=`expr $BB_DOC_SELEND - $BB_DOC_SELSTART` ;
echo SEL_LENGTH $SEL_LENGTH ;
Scripts should be placed in ~/Library/Application Support/BBEdit/Scripts to
appear on BBEdit's Script menu.
HTH,
Jean Jourdain
On Monday, August 30, 2021 at 4:14:56 AM UTC+2 Tim Gray wrote:
> Is AppleScript the best/most powerful way to script text manipulation
> based on where the cursor currently is? I know Text Filters can be very
> useful, but only seem to operate on selected text (or the whole document).
> But I'm looking to modify the current line if nothing is selected or modify
> the selected lines if multiples are selected, even if they are only
> partially so. I'm assuming that AppleScript is the only tool available for
> stuff like this in BBEdit.
>
> Thanks,
> Tim
>
>
--
This is the BBEdit Talk public discussion group. If you have a feature request
or need technical support, please email "[email protected]" rather than
posting here. Follow @bbedit on Twitter: <https://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 view this discussion on the web visit
https://groups.google.com/d/msgid/bbedit/c2eb4de0-e53e-4a60-9e79-dd78b4b94554n%40googlegroups.com.