Removing autocapitalization for a specific combination

Hi,
I am often writing a part number like “at020” and of course, at a beginning of a phrase, it gets automatically capitalized to “At020”.
Can you help me to write my first macro to remove the 1st capital letter only for a particular set of 2 first letters?

Thanks in advance!

It’s probably tricky to spot because Keyboard Maestro wont see the auto correction.

You could have a Typed String trigger with a regex match of something like "\bat\d+ " (\b is a word break, and include the space at the end), and then you could do something like Option-Shift-Left Arrow, Insert Text by Pasting “%TriggerValue%”.

It’s a bit ugly, but it might work.

What app are you using when this autocorrect happens?

If it is like Outlook 2011, you might be able to disable it for specific characters.
Check the Preferences of the app for something like this:

There's also an option in System Preferences > Keyboard > Text:

I am using Mail.

Mail does NOT auto-capitalize the start of sentences for me.
Running Mail 9.3 (3124) on macOS 10.11.6

Have you checked your settings as shown in my above post? I just tried it (macOS 10.12), and Mail is perfectly adhering to the setting.

hi Tom. Thanks! It works but i am looking for a possibility to autocapitalize automatically except when the word (part number in this case) starts with “at”. I am probably making it too complex…

I don’t know if this would work for you, but there are services and KM macros that will capitalize the first word of all selected sentences. If you use the KM macro, you could exclude any words/characters you’d like.

So, the workflow is to type as normal. Then before you send, select all and run the macro.

Typinator is using this regex for auto-capitalization:

(?<![.0-9[:upper:]]|\W\w)[.!?] {1,2}[[:lower:]]

If we tweak this a bit we can use it in KM as a Typed String trigger and get close to what you want:

(?<![.0-9[:upper:]]|\W\w)[.!?] {1,2}(?!at)[[:lower:]].

The drawback is that any "at" will not get auto-capitalized.

We could exclude the pattern at followed by a number but then we would be in trouble with things like "i am" (would become "I Am"), or with things like a preceding "1." or "U.S." which should not trigger the capitalization.

(Probably the macro could be optimized by running the trigger through a second regex instead of the simple filter.)

So, this is far from being perfect, but maybe it's good enough. Just remember to manually capitalize any "at" not followed by a number :wink:

Note: Of course, you have to disable macOS' auto-capitalization feature as shown above.

[test] Auto-Capitalize (Except "at").kmmacros (2.1 KB)

OK, here is an advanced solution that should handle everything properly.

I changed the Trigger regex so that it only excludes "at" followed by a number:

(?<![.0-9[:upper:]]|\W\w)[.!?] {1,2}(?!at\d)[[:lower:]].{2}

This requires to run the trigger string through a second regex. I've done this with Perl but it could certainly also be done with sed or whatever:

perl -s -e '$str =~ /(\P{CWU}*)(.*)/; print $1 . ucfirst($2);' -- -str="$KMVAR_tmp"
  • An "at" (without numbers) is now properly capitalized
  • Something like "at5" or "at567" is not capitalized

The regex should be Unicode compliant, that is, working also with other languages than English

[test] Auto-Capitalize (Except "at number").kmmacros (2.5 KB)


Here is a "pure" KM variant that does pretty much the same (I haven't noticed any difference in speed.):

[test] Auto-Capitalize (Except "at number") [pure KM variant].kmmacros (2.8 KB)

2 Likes