I want to perform actions on each file in a folder

So I start out with “For each Path in a Folder”.

What I want to do to the files is make them into Searchable PDFs, so I say “Activate Searchable PDF Converter”.

But then I get a little Yellow Triangle above right after “For Each Item in a Collection Execute Actions”. When I click on it, I get an “Action Warning”: A For Each action sets the variable for each entry in the collections(s) and performs the enclosed actions. Your actions do not appears to use the variable."

So I tried putting "Set Variable “File to OCR” to Text “%Variable%File to OCR%” but the Yellow Triangle didn’t go away.

What am I doing wrong?

Thanks!

That yellow triangle and error message means you're not using the variable set in the For Each action in the action(s) you want to perform. Here's a basic example showing how to open every file in a folder with a given app:

If you're still not sure how to proceed, please post your full macro so we have a better idea of how to help.

2 Likes

That’s wonderful!

The next thing I would like to do as part of the Action is add “_OCR” to the name of the File or put a color label on the file and/or move the file to another folder.

Sure, that's easy enough:

Perform Actions on Each File in Folder.kmmacros (2.3 KB)

The action to move a file and rename a file is actually the same action, so in this example macro here I've done just that: moved the file from Downloads to Desktop and added the _OCR suffix.

1 Like

Thanks so much. It seemed like it should be that easy, but I looked all around in the User Guide about Variables for how to do that with the color and never got anything so clear.

And the answer to adding “_OCR” is just as easy, but… So if I wanted to add something, say even “_OCR” to the beginning instead of the end, it would be “_OCR%variable%File to OCR%”?

Thanks, again!

I have to apologize: I was hasty with my earlier example, and didn't test it properly. It turns out the process to simultaneously rename a file and move it to another folder is a little more involved than I thought:

Perform Actions on Each File in Folder.kmmacros (3.4 KB)

Essentially, to rename a file and also move it to a different folder, you need to break the file's path down into its separate components (this is easily done using KM8's Split Path action, but this can also be done with previous versions of KM), set the folder to move it to and the new file name individually, then recombine the components in the Move or Rename a File action. To answer your latest question, in this example macro, you can simply change the Set Variable "File Name" action to OCR_%Variable%File Name% to add a prefix instead of a suffix. I hope this all makes sense!

Thanks! I’m glad I didn’t have time to try it out last night. It was more complicated than I thought. At least in spots… I’ll give it a try later today.