How to extract text from images in a folder

I want to be able to collect text from images but Keyboard Maestro's OCR has never worked well for me. For example, I tried to design the following macro to do OCR on each image within a folder (Desktop/t) and append the result to a text file (Desktop/t/Test.txt) and it rarely would work, generally missing most of the data.
Extract Text from images in a folder.kmmacros (8.0 KB)

So I decided to do some testing with 3 images in that folder, debugging by adding pauses of different lengths (0.5 to 2s) or timestamps inserted during each loop. Below are the images, the expected output as well as several examples of the actual (wrong) output I got. I didn't include the correct output, but believe me, it rarely happened.

What can I do to make this work? I'm using KM 11.0.3 on Mac OS 15.3.2 on a MacAir M3.
a
b
c

Expected result:
BLE-YY1030 2025-03-14 16:40:17
pH:4.08,26.4°C,79.5°F
BLE-YY1030 2025-03-14 16:42:17
pH:4.08,26.4°C,79.5°F
BLE-YY1030 2025-03-14 16:46:17
pH:4.08,26.4°C,79.5°F

Example 1:
BLE-YY1030 2025-03-14 16:42:17
pH:4.08,26.4°C,79.5°F

Example 2:
BLE-YY1030 2025-03-14 16:40:17
pH:4.08,26.4°C,79.5°F
BLE-YY1030 2025-03-14 16:46:17
pH:4.08,26.4°C,79.5°F

Examples with times inserted for debugging:

Example 4:
BLE-YY1030 2025-03-14 16:40:17
pH:4.08,26.4°C,79.5°F
17:12:13
BLE-YY1030 2025-03-14 16:42:17
pH:4.08,26.4°C,79.5°F
17:12:19
BLE-YY1030 2025-03-14 16:46:17
pH:4.08,26.4°C,79.5°F
17:12:25

Example 55:
BLE-YY1030 2025-03-14 16:40:17
pH:4.08,26.4°C,79.5°F
17:09:10
BLE-YY1030 2025-03-14 16:42:17
pH:4.08,26.4°C,79.5°F
17:09:15
17:09:20

Example 6:
BLE-YY1030 2025-03-14 16:40:17
pH:4.08,26.4°C,79.5°F
17:10:19
17:10:24
BLE-YY1030 2025-03-14 16:46:17
pH:4.08,26.4°C,79.5°F
17:10:29

For the curious, this data is from a pH meter with terrible software. The iOS app allows the data to be transferred via Bluetooth to a spreadsheet but while collecting data it constantly drops the signal, losing data. That app can also be run on MacOS but it's not designed to and the feature to transfer data to a spreadsheet doesn't work. However, it doesn't drop the Bluetooth connection and will at least show the data on the screen where I can scroll through and at least see it. So if I can just make a KM macro to scroll through that list and grab the data from the screen I'll have a work around.

The main thing you can do is change "Languages - English" to "Apple Text Recognition." That will improve recognition (both speed and accuracy) dramatically. The speed is about 6x faster and the error rate is about 10x lower, in my tests. It's a simple fix - try it and see what happens.

Apple Text Recognition does have a few issues, and I can help you with them if you experience them. For example, it sometimes returns the text in the wrong order if the text is in a table format. But your text looks like it is reasonably structured.

1 Like

That worked amazingly well. I just tested on a more realistic series of images containing about 200 records. I had manually done these and so was able to check and find only half a dozen OCR errors, each of which was inserting or not inserting a space -- so irrelevant. So this is an excellent first test.

The reason I was using "Language - English" is because I often want to do OCR in French, German, Italian -- I had no idea the OCR quality would be so different.

There are a few posts on this forum which discuss the quality and speed of the Apple OCR.

I think Apple OCR does work with French, German and Italian (and 6 more languages.) I'm not sure how you "tell it" to use those languages or if it's entirely automatic. You can test it and let us know. It's probably automatic.

Apple OCR is superb, but it does have a couple of minor problems. For example, I always seem to find that it will only work if there are two or more letters in a row. It can't read a "standalone" letter.