Cycle through files in a folder to Clipboard

I have a folder which contains a number of text files. I would like to have a loop where it reads the contents of those text files into the clipboard, one at a time (so I can process each one). So, I am thinking something along the lines of a For Each command.

Is this possible with KM? I’ve no idea how to do the cycling!



Hey Jon,

Be more specific about the processing process.

Reading the files is easy, but how you’re processing makes all the difference in how to go about it.


See the File > For Each Path in Folder action.

This will get you the path to each file.

Then you can use the actions something like this macro to process each file:
MACRO: [FILE] Process Lines in Text File

Hey Chris, this is what I mean…

A folder contains say 100 text files. So I want a loop that:

  1. Reads the first text file contents into the clipboard. (I have code that then does stuff to the clipboard contents)

  2. Read the second text file contents into the clipboard.

  3. Read the third text…you get the drift!

The loop ends when there are no more text files in the folder.

Hey Jon,

Oh, you're still working on the same problem.

Well, maybe something like this:

Generic-Test 01.kmmacros (4.6 KB)

I've got this set up for manual processing: read the file, pause for user actions.

A second macro changes the variable macroContinues to “Go”, and another iteration starts.

When all files are processed an alert sound goes off.

I know this is not precisely what you're trying to do, but it should give you some idea of how to proceed.


Thanks Chris. It has given me a better idea how the For Each Item in a Collection action works. I can hopefully move forward now. Quick question, why did you put a “.” before /Split_Files/ ?

And yes, I am working at the weekend!

Hey Jon,

I could have written it “Split_Files/”

The dot means current directory, and that notation is more clear to me at a glance.


Ah gotcha, thanks.