Converting Case

I came looking how to convert case like I do in QuicKeys. I am getting down to the point of macros that I haven't quite figured out yet after a year of converting QuicKeys macros to Keyboard Maestro and Chris that is one of them.


The options in QuicKeys seem much more user friendly and what I can find in Keyboard Maestro seems more like a programers mind to figure out what is going to happen and what to change. See how intuitive (at least to me) the macros are for this in QuicKeys.



I guess you probably found this:

and the parallel Filter Variable action.

I can understand the hope of a shorter search route to it, though ...

Hey Skillet,

I used QuicKeys from 1986 until 2012 (when it became clear it would never be updated).

I had been running Keyboard Maestro concurrently on my system since 2003, and it was still quite an effort to get my hundreds of macros switched over.

Changing the case of text with Keyboard Maestro may not be as intuitive as it is in QuicKeys, but it's not difficult

Title Case → Selected Text.kmmacros (2.8 KB)

Titlecase does not automatically change uppercase letters to lower-case, and here's why:

My macro does explicitly lowercase the text before transforming it to titlecase.

If you search the wiki for "change case", or “titlecase”, or “lowercase”, or “uppercase” you'll find the Filter Clipboard and Filter Variable actions.

-Chris

3 Likes

Others have pointed out the filter actions, but basically what you're running up against is a difference in philosophy between Quickeys and Keyboard Maestro.

With Keyboard Maestro, rather than give you a tool that operates on file names in the Finder, I give you three different tools, one to iterate through the Finder selection, one to change the case and once to rename a file, and you put them together like lego blocks.

So yes, if what you are doing fits exactly in to what has been provided natively, the Quickeys approach can be simpler. But as soon as you want to do something slightly different, then you have to do it in an entirely different way, or maybe it is not possible at all.

With Keyboard Maestro, if you want to change the case of all the lines in a variable, the same process applies. Or if you want to rename the files in a different way, the same process applies - you just adjust the part that has changed to match your new requirements.

And yes, that can be a jarring change from what you are used to, but it can also open up whole new things you can do that you could not before, and while it may appear more complicated initially, plugging together several less complicated facilities keeps things simpler as you expand the scope of what you want to do.

2 Likes

Very nice thank you all, I figured Keyboard Maestro had it in there somewhere I just wasn't able to find it after searching.

Thank you for the included macro.

I needed to tweak your very helpful macro post to not have the case change be included in my clipboard history. The funny thing is I found another post you had posted in my search to not botch the system clipboard and the "title case" macro was posted in the forum talking about how to restore clipboard history by copying it first to a temp and then restoring it.

Strange coincidence the same macro also talked about what I wanted to do to the macro.


No doubt, the very nice thing about flexibily comes a degree of complexity and slightly steeper learning curve. I would love to see someone put together a series of tutorials for Keyboard Maestro though I do like what "Asian Efficiency" has done with what he knows on YouTube.


Before:
what in the WOW is going On

After:

  1. what in the wow is going on – lower case
  2. What in the WOW is Going On – Lower Case First
  3. WHAT IN THE WOW IS GOING ON – UPPER CASE
  4. What in the WOW is going On – Upper Case First
  5. What In The Wow Is Going On – Capitalize
  6. What in the WOW Is Going on - Title Case
  7. What in the Wow Is Going on – Title Case With Running Lower Casing First

https://wiki.keyboardmaestro.com/action/Filter_Clipboard

  1. Lowercase (all characters)
  2. Lowercase First (just the first character)
  3. Uppercase (all characters)
  4. Uppercase First (just the first character)
  5. Capitalize (all words)
  6. Title Case (intelligently uppercase certain first letters)

It doesn’t seem like Lowercase First and “Uppercase First” is even working.

Change Case.kmmacros (35.3 KB)


I'll have to work out the missing building block in Keyboard Maestro that changes all the selected items in the Finder to convert the case (it didn't near instentaneously even in El Capitan) since this just does it for selected text rather than selected items in the Finder like I had it before. Much more universally useful though as pointed out by Peter.

Hey Skillet,

Impossible.

Read in particular the yellow caution icon’ed item here: Keyboard Maestro Wiki → Clipboards.

The only time you can bypass the system clipboard is when the app you’re using is AppleScriptable and is able to directly access text or other items.

I think you’re misunderstanding what these do.

Lowercase the first letter.

Uppercase the first letter.

Depending upon what your case is to begin with you may not even see any action.

It doesn’t work with files at all, because the macro is not written to deal with files.

-Chris

Hey Skillet,

You can pare your macros down to this:

QK - (6) Convert Selected Text to Title Case.kmmacros (2.7 KB)

(Actually I don't think you need the pause action with paste, although you would if you used V instead of the Paste action.


Keep in mind that QuicKeys didn't have a Rename Files In The Finder action for a long time. It was something users begged for and eventually got.

With Keyboard Maestro you have to roll-your-own, and I'll get to that in a bit.

-Chris

Hey Skillet,

Okay, I wrote an AppleScript-based change-case macro:

Finder – Change Case of Selected Files

By changing one property in the script you can switch between lower-case, title-case, and upper-case.

Because the file-system isn’t case-sensitive this method should be a bit more efficient than using normal Keyboard Maestro actions.

-Chris

That is very helpful to know, thanks for pointing me to the read about clipboards and the mandate to go through the system clipboard.

Understood, I guess all I was saying is I’ll have to put that on my bucket list to figure out how it is done in Keyboard Maestro. Could use straight up AppleScript I guess. Left that last comment in here for kicks and laughes because I just read your third post that has the AppleScript! Thanks so much Chris, you are outstanding!

That is interesting and even shorter though I am trying to wrap my head around “Past Clipboard 0” instead of 1. I guess that just means the last thing that was in the clipboard. Played around a bit with that removing and adding that action and it goes through the history of the clipboard. I guess that is all retained by Keyboard Maestro and no the system.

If you are still looking for a solution, you might take a look at:

WordService by DevonThink (freeware)

WordService provides a large number of commands for working with selected text:

Reformat text paragraphs
Clean up tabs, quotes, line endings
Remove unwanted text parts
Sort lines or paragraphs
Change case
Shift paragraphs right or left
Obscure using Rotate 13
Insert date, time, or file path
Get text statistics

I am sure I am, I still don’t understand I thought in example 2 above the W in What would have changed to a lower case w.

Very nice thanks.

You’re welcome, Once you install the WordService, then you can assign shortcut keys to each service function (System Preferences > Keyboard > Shortcuts), which you can then obviously call from a KM Macro.

1 Like

WordService is an excellent freeware service – I’ve been using it for so long I don’t remember when it came out.

Anyone who likes it should consider installing CalcService as well.

-Chris

1 Like

Hey Skillet,

PastClipboard 1 really is the first available past clipboard.

PastClipboard 0 is a synonym for the current system clipboard.

My macro above actually puts two items in the clipboard, so I have to pop both of them off the stack to get back to the original current clipboard item.

-Chris

I installed that too. I tried DevonThink Pro Office for a while and since it was too propirtary in storying all of its files and they were still working out the syncing details between computers I stopped using it. They do make some pretty cool software though no doubt.

Interesting the system clipboard retains a history, I didn’t realize that, I thought you needed 3rd party apps to do that. Seems like remove PastClipboard 1 and PastClipboard 0 would result in the same outcome. Thanks for the info, good to learn new tricks.

The Mac OS X System Clipboard does not have a history. It is provided by Keyboard Maestro.

1 Like

That makes much more sense, I kind of suspected that was the case.

Does anyone know how I can only Title Case the first word of a given string? I want to make a macro that will turn a string in my clipboard into a sentence.

So if my clipboard holds this is a cat, after I run a macro I paste This is cat. text. So the first word is title cased and a dot is added in the end.

I am not sure how I can title case only the first word and then add the dot in the end. Should I use python for this?

Based on your example, when you say title case here, it sounds like you just mean "make the first letter of the first word in the string uppercase." Assuming that is indeed the case, this can easily be done in KM with an Uppercase First filter and a regex search-and-replace:

Sentence-ize.kmmacros (1.9 KB)

2 Likes

This is perfect. Thank you @gglick

I somehow missed Uppercase first. I wanted to split string into words and only title case first but this is so much simpler. :smiley:

1 Like