Start snake_case with a keystroke until pressed again?

Hi,

While toggling between cases of selected text is a problem long solved, I couldn't find a solution to what I would like to do.

Is it possible and how would I go about having a keystroke that starts snake_case (or whatever case for that reason) until it is pressed again?

Thanks,
Vedran

Chat Gpt advises me to use Karabiner Elements and Hammerspoon for this but I'd rather not go down two new rabbit holes if Keyboard Maestro can take care of this.

Interesting question. I like this question. Sure, I think I can do it. Although you haven't defined snake case, I think it's when spaces are translated to underscores. Basically then, you want a simple macro that is triggered by a space key and types an underscore whenever it's triggered. Then you need another macro that is your hotkey for enabling or disabling that macro.

I'm not sure if that will meet all your requirements, but you haven't really stated what all your requirements are.

So here's the first macro you need:

And_here_is_the_second_macro_you_need:

It_seems_to_be_working_for_me!_It is working perfectly!

1 Like

What a legend. And with such ease. :sparkles:
Can’t wait to be at my Mac to try this.
Thank you!

Thanks! I didn't test it thoroughly. I'm concerned that there might be a fraction of a second between the time you press the toggle hotkey and the time that the other macro is enabled or disabled. Let me know if that's a problem.

Yours works like a charm.

Inspired by your example, I tried doing one for Title Case.
image
=> It Works If I Deliberately Type Slower After A Space.
=> If Not = hTis sI hWat Happens.

I have tried filtering clipboard, not regexing it, same thing. Regexing it to the source for some reason does not work (thinking it might be a bit faster).
Not sure if there is an option to use the trigger regex and somehow just instantly replacing it?
Don't know how to think, any suggestions on the approach?

I was afraid you were going to ask for Title Case. I need a little time to think about that.

1 Like

It'll work better if you use the trigger options instead of trying to replicate them with actions. Try this:

Dynamic Title Case.kmmacros (1.6 KB)

1 Like

Amazing, Thank You!

Nige is always putting me out of business. How is his solution working for you? I think I have found an entirely different approach.

Indeed, my approach seems to work. Although if I mash the keyboard with 25 characters per second, my method seems to make a few mistakes. I can't understand how my method could make any mistakes. I don't think it makes any mistakes for normal typing speeds, however.

Here is my solution (it's two macros in a group called "Title Case")... But if you like Nige's solution, you can stick with that.

TC Work Macro (v11.0.4)

TC Work.kmmacros (54 KB)

1 Like

Try "Semaphore Lock"ing the whole macro to force sequential execution as you type -- I don't think you can rely on simulated keystrokes hitting the buffer in the correct order when you've multiple near-simultaneous instances of the macro running.

That's probably it! Thanks. I'm such a proponent of semaphores and here I go forgetting about them.

1 Like

Niges method works perfectly. I will have a look at yours too.

To contribute, I have made dynamic uppercase macro.
Though it might be useful for some of us that don't have a designated caps lock key and don't want to be pressing caps word before each word when typing more then one cap word.
Can't really take any credit for it since all I did is change a letter in regex using Niges method, but still.

There should be a trigger macro and the macro that does the work in the folder. (First time sharing a macro to forum)

CASE - UPPER Case -- Dynamic .kmmacros (1.7 KB)

  1. Title Case:
  • Title Case Is On. It Is Working Perfectly. I See No Problems At All. Everything Seems To Be Working Just Fine. I Am Typing At My Normal Speed Of About 80 WPM.
  1. snake_case:
  • write_some_code_here
  1. UPPER CASE:
  • NOW DECLARE SOMETHING

And here is a Macro group with all three Macros and their enablers. For ease of access if anyone interested.

Dynamic Case Change Macros Macros.kmmacros (10 KB)

You really did put some effort in this one. Works great. Thank you for the help!

Thanks. If you need any changes, let me know. I recommend that you place a semaphore at the top to prevent errors that may occur when you type really fast.

1 Like