Selecting and copying lines from a text file


Apologies if this is a simple one, but I'm very new to KM and have got myself in a pinch at work where I need to find a solution ASAP and I'm struggling to find anything one this.

In short, I work as an assistant editor and I am trying to create a series of macros to run on a streamdeck where each button will paste a line of text from a text file. I'm unsure of how to isolate individual lines of text and copy them to the clipboard.

This is the workflow that I want to set up.

  1. A text file will live on my desktop (always named the same) and I will paste multiple lines of text from another source into that document.
  2. My streamdeck will be configured so that each button will be assigned to a line of text, ie, 1,2,3,4,5,6 etc.
  3. When a button on the Streamdeck is pushed, the KM macro will read the corresponding line from the text file into the clipboard.
  4. That line of text will be pasted into my active window

The master text file I'll be reading from will be constantly wiped and updated with new text, so it should be quite simple I hope! The macro just had to read from a certain line and the refer to the line number only, not the text within it - so that when my text file is updated and changed, nothing needs to be edited in the macros.

I'm aware this comes close, or does exactly what I'm after, I'm not sure - but it's a little confusing to me!

Thanks, appreciate any help anyone offers!

Welcome to the KM Forum!

Your question is very straightforward to address using the actions provided by KM.

Here’s the approach needed to get individual line of text from a file:

  • Read the file into a KM variable (called, say, Text)
  • Get the first line of text with this syntax %Variable%Text[1]\n%
  • Get the second line of text with this syntax %Variable%Text[2]\n%
  • Get the third line of text with this syntax %Variable%Text[3]\n%

If you use @corcules KM plugin, you can get each of your Stream Deck keys to run a KM macro with a parameter that KM can access via the token “%TriggerValue%

So the above syntax would become %Variable%Text[%TriggerValue%]\n%

I’m away from my desk so unfortunately I can’t provide an actual macro for you to experiment with. However, by searching this forum and the KM wiki you will find plenty of examples to help you out.

If you have other questions, don’t hesitate to ask!

Thinking a bit more about what you posted it dawned on me that having to press a different key to get a different line seemed unusual and somewhat unnecessary: since KM can “remember” which line of text was last pasted, it can also automatically paste the next line using the same hot-key to trigger the macro. In other words:

  • manually move mouse to 1st input field
  • press hot key
  • paste line 1
  • KM moves mouse to 2nd input field
  • press hot key (the same one)
  • paste line 2
  • KM moves mouse to 3rd input field
  • press hot key
  • paste line 3


Whether this approach would be appropriate is difficult to tell as you haven’t said much about the app involved or the overall workflow you’re trying to automate but it avoids having to set up a bunch of different keys on your Stream Deck. Of course there are plenty of variations on this theme that could also be better suited to your needs.

Thanks tiffle, appreciate the welcome and the fast response!

Basically the workflow involves individually pasting the text into markers in Avid media composer, as a form of transcription. It's a bit of a weird one and a bit difficult to explain the quirks of it breifly, but it works best to have each line assigned to a button on the streamdeck.

Thanks for the explaination, although I'm having some trouble getting it to work. When I set a test up the way you've described (i think!), it's pasting every line from the text file, not just line one in this instance.

This is the contents of my text file:
Line 1
Line 2
Line 3

This is the macro:

And this is what I get when I run the macro:
Line 1
Line 2
Line 31]

Thanks again for your help!

Oops - my mistake. The syntax should be


I missed the % off the end. (I'll correct the original I posted.)

Oh that works a treat! Thanks so much!

1 Like

Great - sorry about the hiccup!