Improved Sentence Case Macro

Do you have a version that produces "Sentence" Case, which observes the same rules as Title case (except of course making 1st char of each word upper case).

The one I have does a lowercase of all first, then caps the first character. Of course, that ruins all of the acronyms etc in the text.

1 Like

JMichaelTX wrote:

So, do you want me to replace your OP with the last update post?
You can certainly do that if you don't think it confuses the subsequent
entries.

I'll look for the yellow updated flag to get an idea of how it's used.

Mike Pasini
mikepasini.com http://www.mikepasini.com
mrpasini@gmail.com mailto:mrpasini@gmail.com

JMichaelTX wrote:

Do you have a version that produces "Sentence" Case, which observes
the same rules as Title case (except of course making 1st char of each
word upper case).

I don't but that should be easy enough. I'll look into it after dinner PT.

Mike Pasini
mikepasini.com http://www.mikepasini.com
mrpasini@gmail.com mailto:mrpasini@gmail.com

JMichaelTX wrote:

Do you have a version that produces "Sentence" Case, which observes
the same rules as Title case (except of course making 1st char of each
word upper case).

Well, not so simple. I'll look at it again tomorrow.

Mike Pasini
mikepasini.com http://www.mikepasini.com
mrpasini@gmail.com mailto:mrpasini@gmail.com

No problem, no rush. I've lived without such a tool for years, so a while longer won't matter.

BTW, when you reply be sure to type below the closing quote tag
[/quote]

Otherwise you're adding to the quote. :wink:

Well, give this one a try.

If it runs into all caps, it lowercases first, otherwise it won't so acronyms survive. It's also wise to quotes and various sentence endings. And it handles a couple of false positives (acronyms with periods are not end-of-sentence and neither are quotes after a comma).

Sentence Case.kmmacros (4.3 KB)

Works well. Many thanks for all your efforts. :+1:

When you have time, would it be possible in the case of all caps to treat acronyms with periods like you do otherwise?

Finally, would it be difficult to use a user-supplied word list of words to always use all caps? I think we may have discussed this before, and I know a common list is huge. But maybe for specific user and/or company and/or industry it might make sense.

Again, not urgent at all. Please work on only when you have the time and interest.

You mean just preserve them? And remove the periods?

The title case macro has a list (small words) of words that should not be capitalized. You could also certainly have a list of acronyms. And you could read that list from a file if it was very long. (Ah, but where would that file live?)

But the sentence case macro works differently. It doesn't look at words like the title case macro. It looks at sentence boundaries and those false positives.

Which means it would just require a separate operation to go through the selection to look for the acronyms. Not a big deal.

Should we move this to a new topic?

Here's v2.0 with a mechanism for listing acronyms. I just have three in there. And I'm stripping periods (first substitution), which you may not prefer.

Not sure at what point I'd use a file to load the acronyms.

Sentence Case.kmmacros (4.4 KB)

1 Like

That's all good. I'll test tomorrow. Thanks again.

Sentence Case Macro

Updated to handle bug capitalizing letters following an apostrophe in contractions. We're just lowering casing them in the fourth line rather than try to fix them in the third line where they are capitalized.

Sentence Case.kmmacros (4.5 KB)

2 Likes

Wow your Macro seems much better than old my approach.
Sentence Case _My Old Approach.kmmacros (25.8 KB)

I essentially did the same with a ton of regex filters and substrings. All with KM actions and no shell/applescript.

Yes, it's an interesting problem (for which, as you can see above) I was drafted. It's a lot harder to identify a sentence than it might seem.

Your macro is an admirable attack on the problem. It also illustrates just how hard it is to use actions to deal with a complex situation in Keyboard Maestro's visual programming language. You can get tied up in knots pretty easily, scrolling around to find out where you are (I'm in the middle of just such a project right now, in fact).

But it's also quite a blessing to be able to run AppleScript, JavaScript, a shell command and any other number of languages from an action. In this case, it's hard to beat Perl's text processing.

It's a lot harder to identify a sentence than it might seem.

Yes, my version was just at start, after line-breaks and after dots. Did not even think of quotation marks or other endings like "!" "?" as in your version.

Yeah I get that too quite often. I guess it's a bit because usually in javascript programming for example you would split up your code into different functions to avoid duplicated code and to make it easier to understand. Of corse in Keyboard Maestro one could split it in different Macros that call each other but usually I end up with just one huge & complicated macro instead.

I think regular expressions is limited by the set of logic is has as its disposal, and can easily get very expensive if trying to cater for every possible form a sentence structure can take.

I think text scanning methods are possibly more well-suited to this situation, as one can define custom logic as they please, and as a string only ends up being processed once, might even be more efficient.

Thank you very much. This is incredible!

Glad you found it helpful!