Convert between Spaced String, Camel Case, Kebab Case and Snake Case

Hi, I would like to be able convert the clipboard text between these formats:

Spaced String: “a string with space”
Camel Case: “AStringWithSpaces”
Kebab Case: “a-string-with-spaces”
Snake Case: “a_string_with_spaces"

Anyone done this or can offer some help? I'm a complete Keyboard Maestro noob.

Just to get you started, using clipboard actions
Copy the string to a named clipboard
Filter Named clipboard action with whatever you want to do to Named Clipboard2
Paste from named clipboard2

You can see your named clipboards via KM Preferences
or you can just display them in your macro, display named clipboard action.

Also search this forum for clipboard and you will get many ideas.

PS Use named clipboards as it is easier to debug.

many thanks for the reply jonathonl. Any thoughts on how I manipulate the strings?

manual:Filters [Keyboard Maestro Wiki] <<<WIKI manual
action:Filter [Keyboard Maestro Wiki] <<<action

use filter action

===================================

For the more unusual ones, if you really really need them, google kebab case javascript etc and insert the regex or javascript into your code

===================================

and, if you really want to get carried away

Hi jonathonl, I think this is all a bit beyond me. Maybe this is not the tool for me.

Many thanks for trying to help though - much appreciated.

Hang on, I did not want to put you off.
Why did you want to do this in the first place?

I'm evaluating at the moment and was thinking of buying. This would be a killer feature for me well worth the ticket price, but the investment in learning how to DYI it is more than I can invest right now.

Any other features you are particularly looking for?

This is the problem I am trying to solve right now, but I like the flexibility of the tool for future needs.

OK give a couple of test cases of the input and your required output, and by tomorrow someone on the forum will probably give you an answer.
Also please read the first few chapters of the pdf I have sent you as that will give you a framework to proceed further.

Is this close to what you want to do?

1 Like

Hi kcwhat, that looks perfect. How do I get this working for me?

I see now - I'l have a play, many thanks! (sorry very new here)

I'll make you the full macro shortly.
First, a non-forum message that you have to promise us... Never... Ever give up on Keyboard Maestro. :slight_smile: Even if it couldn't do one feature, there are tons upon tons of other features that it solves. It's almost like turning down a $9,999 loan, from a bank, because you asked for $10,000. I'm messing around but I'm 99% not.

Anyway, @jonathonl gave you the true blueprint but I just made it visual for you.

Let me know if this build will work.

  1. You highlight the text you want to convert.
  2. You hit a hotkey of your choice - Say shift-command-k
  3. You get a prompt to select which case
  4. You select command-v to paste it in your area.

Will that work or is that about it?

Let me know so we can help. Once we get it there, I'll upload the macro. Deal?

KC

I am blown away by the support here! OK, I'm buying KM. Yes that sounds great, or a separate shortcut for each case type. Ideally it would convert between all case types (Camel Case => Kebab Case => Spaced String, etc.)

Hopefully one day I will be able to help someone else as you both have helped me today.

Do you want it to automatically replace the selected case (as in you are in Pages or text edit)? Or is it you just want to be able to paste it anywhere?

Replace would be ideal

Got it. Once I finish my workout, I'll post the macro.

This is actually a very easy use case for KM, IF you know a little about RegEx.
KM makes Regular Expressions very easy to use. The challenge, of course, is coming up with the RegEx. But if you can't figure it out, you can always google it. Your use case is very common, and very old. I'm sure many have already developed the RegEx for it.

But it looks like @kcwhat has got you on the right track.

I'd just make two comments:

  1. I would NOT use KM Named Clipboards for this use case. The only time you really need a Named Clipboard is when you need to store rich text, images, or other objects. Named Clipboards are harder to use, and take up a lot more storage space on your Mac.
  2. If you happen to find a JavaScript RegEx solution, it almost always easier to use the KM native RegEx tools

Finally, this might be a good place to start:

Getting Started with Keyboard Maestro

For more help, see Getting Started with Keyboard Maestro and the Forum .

@froamer - As promised:

Froamer Macros.kmmacros (25.0 KB)

This includes 4 macros that you can change the hotkey for. None of these use a named clipboard. It will only use the system clipboard.

  • Camel Case with no Spaces
  • Camel Case with Spaces
  • Kebeb Case (lowercase)
  • Snake Case (lowercase)

Let us know if this is what you needed.

KC

Edited to change the name for @froamer