Hey JM,
I did this years ago for someone on the BBEdit-Talk list using the Satimage.osax and a very large list of acronyms (about 1400). The thread on BBEdit-Talk is (here).
The downloadable file has the entire list of acronyms included.
The bare AppleScript has ONLY a sample of the large number of acronyms in the downloadable file.
The variable fixedCaseWordList contains words that are to be formatted as they are IN the list and is very easy to add new items to.
As is the script works on the selection in BBEdit, but that's easy enough to change.
It runs nearly instantly on my system.
-Chris
Change case of selected text to title-case v1.01.zip (20.2 KB)
------------------------------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2015/10/21 17:20
# dMod: 2017/05/18 20:01
# Appl: BBEdit & the Satimage.osax
# Task: Change case of selected text to title-case.
# Libs: None
# Osax: Satimage.osax – http://tinyurl.com/satimage-osaxen
# Tags: @Applescript, @Script, @BBEdit, @Change, @Title, @Case, @Title_Case, @Selected, @Text, @Acronym
------------------------------------------------------------------------------
# SCRIPT REQUIRES INSTALLATION OF THE SATIMAGE.OSAX APPLESCRIPT EXTENSION!
------------------------------------------------------------------------------
set fixedCaseWordList to paragraphs 2 thru -2 of "
a
AFL-CIO
an
and
as
at
but
by
for
from
in
into
it
NAACP
nor
of
on
onto
or
so
the
to
with
"
set lowerCaseWordRegEx to change "(.+)" into "\\\\b\\1\\\\b" in fixedCaseWordList with regexp without case sensitive
set _text to getSelectionOfNamedBBEditWindow(1)
set _text to titlecase _text
set newText to change lowerCaseWordRegEx into fixedCaseWordList in _text with regexp without case sensitive
set newText to change "^(\\w)" into "\\u\\1" in newText with regexp without case sensitive
set newText to change "(\\w)(\\w*)$" into "\\u\\1\\2" in newText with regexp without case sensitive
setBBEditTextSelectionTo(newText)
------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
on getSelectionOfNamedBBEditWindow(_window)
tell application "BBEdit"
if _window = "front" then
set _window to window (name of front text window)
else if class of _window = integer or class of _window = text then
set _window to text window _window
end if
tell _window to return contents of selection
end tell
end getSelectionOfNamedBBEditWindow
------------------------------------------------------------------------------
on setBBEditTextSelectionTo(_text)
tell application "BBEdit" to set contents of selection's text to _text
end setBBEditTextSelectionTo
------------------------------------------------------------------------------