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

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

Thank you!

I wound up buying TextSoap, as things like this are tedious in KM. I’m learning it would be easier for me to write a Ruby (sed, etc) script as figure out how to do it in Keyboard Maestro. Edit: TextSoap is easy to call from PopClip too.

I do appreciate the help though.

Thanks so much KC, this is enough for me to learn some more. It works if you start with a string with spaces, but it doesn't convert between each type of case (e.g. Camel Case => Kebab Case => String with spaces).

Also strangely it conflicts with Alfred (launcher) causing the Alfred search bar to appear when one of the macros are run. More research for me.

Thanks for all your help! Amazing!

@froamer - Understood. I've modified the macros so that you can ctrl-z (undo) the selection if you don't like the case you selected. I kept the macros separated as you requested.

So if you make the selection "a string with space", you select your chosen case. If you don't like it, control-z and hot key the one you want. Make sense?

As for your Alfred, problem. There may be a conflict hotkey. Make sure you change the hotkey , that I've selected, to suit your own. For example, the hotkey control-shift-option-command-9 to control-option-command 9 or whatever you chose.

Here is the new Macro group - version 1.0.2.

Froamer Macros.kmmacros (25.8 KB)

For the record, there are many ways to do this, in KM. This is just one simple way. This can be created with Switch/Cases and loops I suppose.

Try it out and lets us know what you think

KC

Many thanks KC, I'll have a play

Great macros thank you!
I have been working on something like this for a while with another twist:
using like in MS Word ⇧F3 to cycle the selection to lowercase, UPPERCASE, Title Case, Sentence case.
This could be further refined by using a RegEx to evaluate the string and if lowercase start the cycle with Title Case etc, if UPPERCASE start with lowercase etc.