How to repeat a type keystroke action multiple times

There's no way on Earth I'll sit still while 100 characters get typed out (unless I have no other choice).

This macro uses a typed-trigger with a regular expression.

Type:

-
or
–
or
_

And then a number followed by a space.

The string will be expanded to the length of the number and pasted.

This macro can easily be modified to be more general OR more specific.

-Chris


Typed Trigger Repeated #-Times.kmmacros (5.0 KB)

2 Likes

Reading all the comments I can see that my macro could be improved substantial.
But I have to say that I use it mostly for repeating up to 20 items.
And it is normally one character.
Here I do not experience any performance issues.

I can also imagine that seeing a solution using simple and native KM actions could be helpfull for people learning to use KM.

But still thanks for all the optimization tips. They are helpful. :slight_smile:

1 Like

Thank you for your reply.
I am curious to ask : in what context would you want to repeat text multiple times?
I apologize for my badly formulated question: I was proposing a solution (repeat underscore) instead of asking a clear question (I want to draw a line in pages).

it’s all my fault for not asking the question properly. My question should have been flagged as ‘inappropriate’ and below the IQ level of forum members !

1 Like

thank you

thank you very much. Where would I find your clipboard macro ? why is it called clipboard and not ‘draw a line’ macro ?

Sometimes I have to insert x number of 0s to control formatting in Excel.
This is primarily the reason

1 Like

thank you

Probably the best way to create a horizontal line/rule in Apple Pages, is to use Pages' native tools.

See Pages for Mac: Add borders and rules (lines)

Also, I have just posted a macro that should work in most rich text apps (but NOT Pages and MS Word):

1 Like

Agreed.

However, I would suggest first building the string, and then pasting it, rather than pasting N times, or even worse, typing N times.

For example:

2 Likes

thank you. It’s over my head for the moment, but I am working hard to improve.

thank you.

Hey Ronald,

Give yourself time. Keyboard Maestro is a pretty complex beastie.  :smile:

If you want to insert a line of fixed length then simply set the clipboard to the text and then paste it.

-Chris


Generic-Test 01.kmmacros (2.0 KB)

1 Like

great. thank you.

I have an interesting variation of this where I need N left arrows. I can’t think of any way other than to Type a Character inside of a repeat statement. It’s awfully tedious to watch when the repetition gets up towards 50 or 100 times. Is there a better way to get N characters that move the cursor but don’t type any “real” characters?

Does this help?

The only way to improve it (baring the application being especially scriptable) is to move by words if that can be appropriate.

Changing the Simulate Normal Keystroke to 0 is unlikely to do anything except lose some of those left arrows and make the process unreliable.

1 Like

Hey Mitchell,

What kind of application?

Please provide more details.

-Chris

I need N left and right arrows in the context of text editing in any application where you can edit text. That’s basically it.

Specifically, after copying the selection, replacing it with some other stuff, and pasting the former selection back, I want to reselect not just the former selection, but the characters I added. Since few applications provide a way to work with the selection, and those that do don’t make it easy, and in any case use different mechanisms from each other, I am left having to do this in a general way. I know how many characters there are in the copied selection, and I know how many characters I have added and where I added them. Thus, I can use a series of right and left arrows (some with shift down) to select the new text along with the old. But it is slow and strange.

No, I don’t know if these are characters, words, lines, paragraphs, or pages, or even which of these the application knows how to deal with.

Other than extensively AppleScriptable apps, I think you’re out of luck. Only individual arrow keys will have any chance of working reliably (no two applications define a “word” in the same way (except by random good luck), so Option-arrow keys wont work).

If you just want to move the cursor, you could do something like:

  • Set Find Pasteboard to “H3R3” (unique code)
  • Insert text “H3R3”
  • Paste One thing
  • Paste Another thing
  • Type Keystroke: Command-Shift-G
  • Type Keystroke: Delete

But you want to select, and there isn’t any way to “extend selection to Find location” (unfortunately!).