Improved Title Case Macro

New & Improved Title Case

The built-in title case filter in Keyboard Maestro distinguishes between "small words" that should not be capitalized and words that should but it doesn't recognize acronyms or handle hashtags and @ words.

Take, for example, these fake headlines:

The sub-report of the ACI committee
C.I.A. Defeats F.B.I. in Smart Softball match-up
Lightroom CC Includes Significant ACR Revisions
OpticsPro takes on lightroom cc and phase one capture one pro
The #MeToo movement gains momentum
Use @SomeoneElse to contact your congressman

This is how the built-in filter applies capitalization:

The Sub-Report of the ACI Committee
CIA Defeats FBI In Smart Softball Match-Up
Lightroom CC Includes Significant ACR Revisions
OpticsPro Takes on Lightroom Cc and Phase One Capture One Pro
The #MeToo Movement Gains Momentum
Use @SomeoneElse to Contact Your Congressman

John Gruber wrote a Perl routine in 2008 to handle title case which was refined that same year by Aristotle Pagaltzis and put in the public doman (https://gist.github.com/gruber/9f9e8650d68b13ce4d78). It applies capitalization to those same headlines like this:

The Sub-Report of the ACI Committee
C.I.A. Defeats F.B.I. In Smart Softball Match-Up
Lightroom CC Includes Significant ACR Revisions
OpticsPro takes on lightroom cc and phase one capture one pro

The main difference is that when the Gruber/Pagaltzis routine detects an acronym, it leaves it alone, although it won't presume one if it's lowercase.

THIS REVISION

In this revision of the Keyboard Maestro macro, we added UTF-8 handling and changed a forced lower-case initial for hastags and @ words to simply leaving them alone (along with file paths).

We also introduced an exception that strips periods from acronymns.

A commented version of the code accompanies the .zip file to make it easier to eliminate that feature or add other exceptions.

USAGE

Select the text you want to convert and type the Hot Key, which has been set to Shift-Option-T. Your selection will be replaced with the capitalized string.

TitleCase.3.zip (4.7 KB)

3 Likes