Copy lines from text file and paste it with leading 0

Hy,
I tried some scripts but I had no luck so I need your help please.
I need a macro that copies the first line from a text file. Then a simple mouse click, type the copied values and press Enter. Do this with all lines in the text file. But there is a problem because the text file contains numbers that looks like that:
001
002
003...
Keyboard Maestro does not type the "00", just the numbers. Can you help me please?
Thanks a lot

If you are doing this with "all the lines of the text file", as you say, then there's no need to process each line individually. You can just read the whole file into a variable and then paste the entire variable into the app you are using. But you didn't say which app you were using, and you didn't show your macro. I'm going to make an assumption about the app, and the filename, and here's a three line solution that should solve the problem.

If the leading zeros are being omitted, that could be because you are using an action that treats the string as a number, and KM variables remove leading zeros from numbers. If you show your code I may be able to spot the problem.

Hy Airy,
thanks for your answer. I need to process each line one by one. The idea is simple. I have to type the values into an app in my office. But this takes very long. So I try to find a faster way. So I tried it with KM. I tried it with this script....
Process Lines in Text File copy.kmmacros (19.1 KB)

But the leading 00 are not typed...

Correct. The leading zeros are not types because you are using the following action:

That is a numerical action which converts strings to numbers, and then returns the number to a string, but numbers don't have leading zeros.

You can force leading zeros, to be printed, but before I tell you how, I want to ask why you are doing this. All you are doing is pasting increasing numbers. You aren't pasting the lines of the file. That's your biggest problem. All your macro is doing is trying to paste numbers. In your original post, you said you wanted to paste the lines of the file itself, which you are strong in the variable called "SingleLine" but you are not referencing that variable anywhere in your macro.

If you really want line numbers printed along with the text, that's also easily solved by modifying my original solution a little bit. In that case your macro can be greatly simplified.

I think what you should do is show actual examples of input and output so we know what you are trying to achieve. Give an example of a file's content and then give an example of the output you want to insert into your app.

The lines in the text file are like this:
001
245
021
006
259
034
003....

I have to type these numbers in an App in my Office. They must be typed in exactly. One after another. The keystrokes after pasting are to get the next free input box in the App.

Did you understand my point that you have a major bug in your macro because you are not pasting the value of SingleLine but instead you are pasting the value of LineNo which is being incremented by 1 each time your macro loops?

If you fix this, your leading zero problem will probably disappear.

The problem is that I do not know how to fix this....

Part of that is because you are working from a very old demo macro. Things have moved on since then.

If you look at the KM Wiki "Actions" page you'll see a "Prompt for File" action, a "For Each" action, and an "Insert Text by Typing" action.

So you can choose a file then type out its contents one line at a time, remembering to include the other keystrokes etc to move between input boxes. For example:

Type File Contents Line by Line.kmmacros (4.4 KB)

Image

THANK YOU VERY MUCH. This helps me a lot.
Kind Regards