I have a question for file numbering macro

First of all thank you for your help. I'm sure the macro I'm asking for is there, but I'm having trouble finding the right search term. I am using only a few useful macros without any knowledge of coding terms or methods.

For example, let's say you have several files. a1, a2, a3..ect.

When you want to rename these files, change a1 to file1, then drag and copy the file1 text, and then paste it into the rest of a2 and a3, so it will be sequentially pasted into file2 and file3.

There are many apps that do this, but it seems cumbersome when you want to change the names of a few files uploaded to the web or in the finder.

The important thing is that the file name does not start with file1, so if file25 was the last changed file, when you drag and paste file25, it will be recognized as file26, and the file name will be sequentially increased by 1 and pasted.

I saw a macro here in the macro sharing room that increases folder copy by 1 in the way I want, but I couldn't modify it and use it.

In summary, it seems like a relatively simple task.

  1. Copy the file name.
  2. Save to clipboard
  3. The last digit increases by 1.

I couldn't try it because I didn't know coding terms or methods.

You can create a new macro or post a link. Thank you for reading this long post.

It seems to me that your explanation includes intervening steps that may not be required to achieve your desired results. I just want to understand the desired results more clearly, without discussing the steps involved. Are you trying to take the contents of a set of files and merge them together?

As I'm writing this, I can see someone else is also writing a response. Maybe their response will be more helpful than mine.

It is possible to make a Keyboard Maestro Macro to rename and number selected files in the Finder.

But before doing this, it is also possible to do this directly in the Finder without any Macro or extra App.

Select the files you want to rename and number in the Finder, right-click and choose "Rename..." from the contextual menu.

Rename files, folders and disks on Mac – Apple Support (UK).

1 Like

Maybe you are right, this isn't about the files' contents, it's just about renaming the files. I thought he wanted to concatenate the contents, but maybe I was wring.

I think I made the explanation difficult. Simply put, I want a macro that can increase the number at the end of a file pasted with a hot key by 1.(text) thank you.

I created a macro that is triggered by a hotkey that increases the number at the end of "the currently selected file" by 1.

I took extra steps to make sure it works whether or not your file has an extension. In your examples there was no extension, but I figured you probably wanted that to work too. You may have just forgot to indicate that you wanted this to work on files with extensions.

In your last message, you had the word "(text)" in your last sentence. I'm not sure what that meant, so maybe I misinterpreted your request. If that had any special meaning, I can probably fix my macro.

Here is the macro. It's pretty simple. Feel free to modify it or ask me for modifications.

Increase Filename By 1 Macro (v11.0.3)

Increase Filename By 1.kmmacros (4.5 KB)

First of all, thank you. But it's not working, what I'm trying to do is copy the letters from the document editor, notes, etc. and increase the number by 1 like you said. I'll try to write it out again below.

drag text1

paste then text2

one more paste then text3

one more text4

I want the above process to automatically sequentially increment to text2, text3 each time I paste it with the hot key. I'm not trying to create a new file or duplicate it, so I look forward to your help once again.

I may not be the sharpest guy on this website, but I enjoy helping people, and I want to help you too. But I'm still at least 50% unable to understand what you want. Phrases that I can't understand are:

  • "I'm trying to copy the letters form the document editor, notes, etc"
  • "drag text1"
  • "paste then text2"
  • "one more paste then text3"
  • "one more text4"
  • "each time I paste it with the hot key".

You don't have to take my advice, but my suggestion is that you do one of the following things:

  • make a video of you doing your work manually, so we can see what you are trying to do; or
  • show a "before" and "after" of your files without explaining the "process". We can figure out the best process.

I won't blame you if you are frustrated by my lack of understanding. But I do want to help.

1 Like


it simple, all text with numbers at the end.

I want to increment the number by 1. Every time I paste it (cmd+v).

Oh I see. So you aren't changing filenames at all. Files have nothing to do with the problem at all. You are just trying to change strings in a file. Let me reconsider. That video helped a lot. I'm not 100% sure I understand the problem perfectly now, but I'm much closer. Let me re-watch your video a few times.

This macro might be one step closer to a solution for you. It's a simple macro, with just two actions, but I think it does most of what you want. I might be able to improve it, but in order to do that I need to know which app you are using. When it comes to dealing with text, different apps have different features.

What this macro does is increase the string of digits that is stored at the end of the string in the system clipboard and then pastes the new updated string into the file you are editing with the new value.

It's up to you to "capture" the first string, for example, "File50". If you place that string in the clipboard, then each time you press F1 you will get File51 File52 File53 and so on.

This should be much closer to what you want. However I have a hunch it's not precisely what you want. Try it out, and tell me how you want it improved. Or if I'm totally wrong, let me know.

Don't forget to tell me what app you are using. Different apps have different ways of handling selected text.

Capture/Increase name Macro (v11.0.3)

Capture-Increase name.kmmacros (1.9 KB)

Thank you. Now you seem to know almost perfectly what I want.

By the way, I'm not trying to capture, I'm simply copying the whole thing, like a triple mouse click.

This is what chat gtp told me when I asked, and I think you can see what I mean by this.

set startNumber to 1
set increment to 1

display dialog "1:" default answer "1"
set startNumber to (text returned of result) as integer

display dialog "1:" default answer "1"
set increment to (text returned of result) as integer

set theText to ""
repeat 10 times --
set theText to theText & startNumber & return
set startNumber to startNumber + increment
end repeat

set the clipboard to theText

I just want it to automatically increase by 1 on the next paste when the text I'm copying contains a number.

My code doesn't capture anything. It's up to you to use CMD-C to copy the string that you want to duplicate.

I don't know what that means. There is no triple mouse click meaning in macOS. You will have to tell me what you mean.

That's precisely what my macro does. When the text you copy with CMD-C contains a number, the next time you use my macro by pressing F1, it will increment that number.

Eg. if you copy a string, eg,


Then when you press F1 it will display:


Then press F1 again it will display:


You showed me some code from ChatGPT. Did you try it? Did it work? If it worked, feel free to use it. If it didn't work, you will have to tell me what it did wrong. Showing me code from ChatGPT won't help me understand what you want if the code doesn't work.

Did you try my macro? You didn't say if you tried it. What did it do incorrectly?

Oh thank you so much. It's working fine now. It's perfect. God bless you!

1 Like

You're welcome. Thanks for the blessing.

I hope you don't mind, but I'd like to correct one thing: please look at the capture. Is that possible?

Jun-12-2024 11-03-47

Are you saying you want (up to) one leading zero when the number is output? It's hard for me to tell because whatever you are using to record your video, it doesn't tell me what keys you are pressing. But if I'm right you want to open the macro and then change...




If you make that change, then the numbers will come out with a single leading zero.

If you want two leading zeros, then change 00 to 000.

Apart from the leading zero, was my macro doing what you want?

This works fine, but the '
' before it is cut off. Can you include it?

Jun-12-2024 16-06-47

Oops. Let me try again. It didn't used to do that. Let me check....

Oh right, that's because you put a dot in the string. I think I can fix that. Give me a minute. Previously I only tested with strings without dots.

Oh wait, it wasn't the dot, it was the extra digits before the last group of digits. Let me think for another minute.

Here, this seems to solve the problem. But as always, you will have to test it to see if it works for all your cases. I did only minimal testing. I'm not even sure if my solution is optimal or not, as I'm not very skilled with regex.

Increase String By 1 Macro (v11.0.3)

Increase String By 1.kmmacros (2.1 KB)

I will probably be AFK for 8+ hours now. See you tomorrow.