Improved Title Case Macro

scripting

#21

You don’t need either a Named Clipboard, nor a Display Clipboard.

Since the macro adds two items to the System Clipboard History, you just need to delete them at the end of the macro, and the item on the System Clipboard (ready to paste) is what you had before you triggered the macro:

Each of these deletes the top (current) Clipboard item.

This is all you need:

###MACRO:   Improved Title Case Ver 2.2 (Del CB 2X) @JMichaelTX

~~~ VER: 2.2    2017-05-26 ~~~

####DOWNLOAD:
Improved Title Case Ver 2.2 (Del CB 2X) @JMichaelTX.kmmacros (5.0 KB)

Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.



#22

Ah. That was my mistake. I was only deleting past clipboard once. Thank you both!


#23

For a built-in locale-sensitive variant:

Copy as Title Case.kmmacros (18.7 KB)


JavaScript for Automation source code

$(Application('Keyboard Maestro Engine').getvariable('itcHeadline'))
    .capitalizedStringWithLocale($.NSLocale.currentLocale).js

Bug report: Title case fails after smart apostrophe
#24

Hey Folks,

I made a minor bug-fix to my script in post 17 above.

-Chris


#25

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)


Improved Sentence Case Macro
#26

@mrpasini, I see with your update that you have included the text of your OP, for completeness. Good idea.

I think the time period in which you can update of your OP has passed. Would you like me to replace your OP with this post? OR, at the very least, add a notice/link to your update post so that readers will be aware of the latest update?

Please let me know your preference.


#27

I hadn’t actually thought of updating the original post because there was an ongoing conversation.

I wouldn’t mind disabling the prior two versions in favor of the latest but I didn’t see a way to do that.

The text for the most recent update does restate the issue but adds to it, explaining what’s new, so they aren’t equivalent. But the original is certainly obsolete.

How should I handle this in the future?


#28

So, do you want me to replace your OP with the last update post?

The usual, unofficial, procedure for anything posted in the “Macro Library” is to keep the OP updated to the latest version, unless there is reason to do otherwise. So we usually insert some type of "Updated: date/time" along with Ver: n.nn <Ver Date>

Unfortunately, the original poster is limited to about 1 or 2 months for updating the post.

I have a yellow “updated” image which looks like this:
updated

The source is:

<img src="/uploads/default/original/2X/9/9fa034801953dfe7d1745afcb7087c7530a06e23.gif" width="70" height="17"  alt="updated" title="updated"> 

This utilizes an existing image. Everyone is welcome to use it you like.
Some prefer to just use a heading style, like ### Updated, which looks like this:

Updated

Use whichever you prefer.


#29

9 posts were split to a new topic: Improved Sentence Case Macro


#34

[/quote]

That reply came from my email client (Postbox), which would not know the forum’s requirements. Could it be a parsing issue with the forum’s software?


#35

I’ve got a three-liner at the moment that handles the following cases, but the thought occurred to me to run these by you to see if they are what you’re dealing with. If not, send me a sample and I’ll work it out.

Here are my test cases:

Before: THE FBI SAID IT WAS CONDUCTING FORENSIC TESTING OF TWO-YEAR OLD HASHTAGS.

After: The fbi said it was conducting forensic testing of two-year old hashtags.

Before: This is a sentence… “well, so is this.” and this too! but what about this one? that, too.

After: This is a sentence… “Well, so is this.” And this too! But what about this one? That, too.

Before: Joseph Grundfest, a commissioner at the S.E.C. in the 1980s and now a professor at Stanford, said he had been contacting current SEC officials and staff to urge them to bring cases, and fast. “it’s more than the extent of the violation,” he said. a spokeswoman for the S.E.C. did not respond to a request for comment.

After: Joseph Grundfest, a commissioner at the S.E.C. in the 1980s and now a professor at Stanford, said he had been contacting current SEC officials and staff to urge them to bring cases, and fast. “It’s more than the extent of the violation,” he said. A spokeswoman for the S.E.C. did not respond to a request for comment.


#40

Yes. I’ll do that now.