Repeat text x number of times

Repeat text x number of times

I use this macro to insert a specified text x number of times.

Insert x number of times.kmmacros (2.6 KB)

Iā€™m not sure if this would make a difference in performance, but it might depending on the app you are typing/pasting into.

Use this JXA script to generate the repeated text, and then do ONE paste.

function run() {
  'use strict';
  var kme = Application('Keyboard Maestro Engine')
  var qtyToRepeat  = kme.getvariable('Repeat Times') || 40;
  var textToRepeat = kme.getvariable('Repeat Text') || "~";
  var filledStr = repeatString(textToRepeat, qtyToRepeat)
  return filledStr


function repeatString(pStrToRepeat, pQtyToRepeat){

  if (pQtyToRepeat < 1) return '';
  var result = '';
  while (pQtyToRepeat > 0) {
    if (pQtyToRepeat & 1) result += pStrToRepeat;
    pQtyToRepeat >>= 1, pStrToRepeat += pStrToRepeat;
  return result;

1 Like


Up until now there has not been a performance issue.
But I will keep this script in mind.