Insert Text (Type Over Text or Overwrite Text when Typing)

This seems like it should be a simple macro, but for some reason I can't figure it out. I've done searching on the forums and I've read into text manipulation and replacement on the wiki. So if someone could help me out, I'd greatly appreciate it.

All I'd like to do is replicate the "Insert" key that is standard on Windows keyboards. I'm sure most of you know what I'm talking about.

For those who are unaware, when I press the insert key on a Windows machine, it makes it so my typing overwrites any text or spaces that lie in front of my current position in the text. So for each letter I type it deletes the same amount. When I press it again, it goes back to inserting the text at the current cursor position. So the insert key toggles between these two states.

I have some template documents, emails, folder structures, etc. with placeholder values that I'd like to be able to type over and replace, while maintaining text afterward, and without having to type and then manually delete.

The macro seems simple. It would just toggle on with a hot key press and for each character typed on my keyboard it would forward delete a character. I just don't know know what action to use for it to count each keystroke.

I've tried exploring the "while" and "for" actions, but with no luck.

And playing around with it, I know I should have some sort of palette or notification telling me it is enabled.

Any help would be greatly appreciated. Thanks

That's an interesting idea. But the answer may depend greatly on which application you want this "overwrite mode" to work in. Do you want it to work in a specific app or in all macOS apps? Since you didn't specify an app I presume you mean all apps.

I like your idea. I might even have a solution for you. But I want you to clarify first which apps you want this to work in.

I think I have a solution, but my solution has limitations. For example, I don't think there's any way for KM to tell if the application you are in is currently in a text field or not. As a result it will simply "assume" that you are in a text field. So that may sometimes be a wrong assumption. Also some apps may have direct support for "overwrite" mode and therefore my solution may cause problems in that situation.

But I think I have a very simple solution to a very interesting problem.

@Sleepy
Thanks for your offer to help.
That is an important distinction. First and foremost would be in Finder. If I can get it working in finder I would be a happy man.

After that it would be Word, outlook, textedit and maybe chrome.

But if we start with finder that'd be great. In that case I have a template folder structure with long code and I need to replace part of that code. So I hit enter, to edit the name of the folder or doc, use my cursor to get the block of text that is there as a placeholder, and then I'd like to trigger this macro, type our the 5 or so characters needed (varies), have it forward delete the same amount characters I just inserted, and then turn off the macro.

I think I'll take a stab at writing my solution for you. I'll keep Finder in mind as the target application for the moment. It may need some adjustments to work with other apps.

I was about to take lunch break but your challenge is far more interesting than food.

1 Like

I'm comfortable working under that assumption, because it would be up to me to make that distinction and my own fault if I trigger it incorrectly.

Though, having a notification or signal, which would indicate that the macro is currently enabled would be very nice.

This should work:

Keyboard Maestro 8.2.4 Actions

Keyboard Maestro Actions.kmactions (2.3 KB)

I think he wants a solution that works more like INSERT/OVERWRITE mode in Windows. I've just written a draft solution that doesn't quite work 100% but I'm going to post it anyway as a starting point.

1 Like

As for the key that changes the mode from INSERT to OVERWRITE, I haven't thought about that yet. That's a trivial part of the problem and I'll deal with that later.

As for the feedback mechanism that tells you whether you are in INSERT of OVERWRITE mode, that's interesting but I'm not worried about that yet. For example, we may be able to put an indicator in the macOS status bar. Or we may use an audio cue.

As a temporary restriction (safety mechanism) to make sure this doesn't mess up other apps, we will put the macro into its own Macro Group and in that Macro Group we will indicate that this macro will work only when Textedit is running:

image

But as for the meat of the problem, here's an early stab at it. It currently only works with the letters "a", "b" and "c". But it's easy enough to extend that if it works. And for the moment it actually does work.

It only works with lower case at the moment.

I think with a little more time and effort we can make this work exactly as you want. I'm not sure if I can compress this macro to work without adding a line of code for each key on the keyboard. That actually may be possible, but I will tackle that later.

I liked your idea.

@thoffman666
Thanks
That does seem like it would work. I'll have to test. I hadn't thought about a generic prompt. I'd gone down the deep end of having a ton of prompts for all these templates and instances, but updating was a pain, so I'd ruled it out. But a generic one that just spits out the text and deletes might work.

Thanks. It's a starting point. I think there are ways to make this work better, but they will take some time to solve.

@Sleepy
Thats an interesting solution. I hadn't thought about using each key as the hot key. It does work perfectly. But it would appear to be quite labor intensive to program each and every character on the keyboard to work as a hot key and switch.

On a scale of zero to 100, I would rate this as a 5 or less on the labor intensiveness scale.

It depends however on how to deal with capital letters. I hadn't solved that yet.

@thoffman666

That action works perfectly as you've designed it. In use it is great. The only, only, downside is when I have a lot of things to insert, I have to repeatedly fire off the macro after I've moved my cursor, rather than the ideal solution, which would be to just move my cursor and continue typing.

@Sleepy

haha. It is all relative, I guess. I'm afraid to see the macros you've programmed higher up that scale. Excited to see what you come up with. Thanks again.

I don't think it's possible to have a solution that doesn't fire off on each key press. I'm not sure why you would call that a downside. Why is it a problem? The user will never know (well, actually in my preliminary tests I can sometimes see the insert/delete with my eyes. Apparently the response time isn't instantaneous. That's an annoyance.

I guess I'm not the first to solve this problem:

He didn't indicate exactly what he did but it sounded quite similar (but not identical) to my approach.

@Sleepy
Oh sorry. That was in response to the solution posted by @thoffman666 in which I'd have to fire off the macro each time I wanted to insert text. Please disregard.

My bad.

I actually found that same post months ago when I first search for this and gave up. I'd forgotten about it. Unfortunately he didn't post the solution anywhere that I can find. But, yes, it would appear your approach is similar. The way I'm reading it, he might have had a different macro for each key.