Automatically duplicate+ rename and archive old file: what is the best approach?

I’m a teacher. Every Sunday I have to write a plan for the next week.
I use Numbers for this.

I’ll try to explain my usual workflow: Before every week I have to write a plan for my class. It’s a combination of stuff I teach my students, the schools I have to drive to each day and my timetable.
1/3 of the document stays the same for the year, 1/3 changes every month and 1/3 of the document changes every week.
Usually I duplicate the file and rename it by hand. It’s called “weekly plan_school week 11”. The duplicate has the name “weekly plan_school week 11_copy”. I rename it to the coming week: “weekly plan_school week 12”.
Then I drag the old file into an archive folder so I always can return and look what we have done in a week.

I tried Keyboard Maestro to do this. But I failed. I just bought KM and I absolutely have no idea what I’m doing. I’m learning stuff, but I’ll need some time and I’m wondering if KM is the right app to do this.

Now I’m thinking about buying Hazel for it. Or is there a better way? I’m really thankful for any idea.

So you need to:

  • duplicate a file that always has the same name except the last x characters
  • move the original to the archive folder
  • rename the duplicate

Is that right?

If so, Keyboard Maestro can definitely do this, but there’s a learning curve.

In general, my approach would be to get the file name of the original, set it as a variable, increment the variable by one, duplicate the file, move the original, rename the copy with the new variable. You can get fancier by deriving the file name from the date, for example.

Another simpler option may be to have a “current week” file that gets named to “archive_date” when moved to the archive folder. Hazel can do that pretty easily.

Share your thoughts and we’ll see if we can help further.


You have a Numbers document " Weekly Plan". On Sunday at the end of week 1, you export a pdf “Weekly Plan_Week 01”. You would have a searchable archived record of week 1.(I’m assuming you don’t need to edit the older documents). You always use the same Numbers document, and each week export a pdf. If you use Time Machine (or some other backup system) you could always retrieve an older version of the numbers document, if need be. Numbers also has a “Revert To” a previous version. I’ve never used this but I need to look into this for myself.

Just a thought.


Thank you for your reply. This is exactly what I’m trying to do.
I’d love to make a macro that does this in Keyboard Maestro but honestly I feel like I’m poking in the hay.
So far the best thing I could find was this tutorial:

But the beginning is different. I’m not sure how to get the file name of the original and set it as a variable.

Next add a Set Variable to Calculation action. You’ll also find it in the Variables Category . Give it the variable name FileNameCounter and have it set to 1 .

This is the easy part.

The final thing to do is have the FileNameCounter variable cycle by one. Add a Set Variable to Calculation action and have it Set Variable FileNameCounter to FileNameCounter+1 .

This I also understand. But the part in between is about setting all files he is selecting as variable in a folder.
I want to do it with just one file.

Thank you, too. I never thought about your whole pdf idea. This sounds good, too. I would prefer to still have changeable Number documents in the archive. Every year I get some new kids and the introduction to the German language is always the same. So I take last years weekly plan, adjust it to the new kids and their needs and save a lot of work. So it’s easier for me to take last years plan of week 1 and delete the stuff I won’t need and add the new stuff I’m doing.

Yes, I can see where that would be preferable.

I’m sure someone here can help you. Between Hazel, Automator, Shortcuts, Keyboard Maestro, etc there is a solution. Also, try cross-posting this to the Automators discourse.

Making your own custom Numbers templates may help with this as well.

1 Like

Thank you, I just revamped my base document, didn’t think about making templates. I will now.

1 Like

If you want to do it in KM, I put together a sample macro that demonstrates how this could work.

This example finds Numbers files in the folder on your desktop called “1”, duplicates the original, renames the duplicate by an increment of 1 based on the original file name (assuming the file name is a number, like “1.Numbers” - otherwise it will fail), moves the original to the folder on your desktop “2”

This should get you a good idea of the possibilities and how you might structure your macro.

Download the macro here if you want to give it a try:
Duplicate Rename and Move Numbers File.kmmacros

Be sure to read the notes and keep in mind this is quick and dirty just to show the concept.


Awesome! It works! It does exactly what I want. Now I just have to figure out how to keep the part of the name that is not a number or how a name and number combination would work… This is great. Thank you so much!

May I ask: Why do I need all these variables and stuff? Couldn’t I just open folder paths where there is the folder icon and define a specific folder?

Yours is the naive approach and could work but after a little experience you would stop doing it that way.

  1. In programming, there is always more than one way to do something.
  2. Well-chosen variable names can help make your code more understandable, especially if you have to revisit it later.
  3. If you use a folder name, for example, more than once, you can instead use the same variable name. And if you decide to use a different folder, there is only one place to change the value.

You certainly could consolidate the steps for a very specific use. I did it more modularly a d included the text window so you could see steps that might help you customize your workflow. I tend to prefer using the variables anyway for a variety of reasons, like making changes easily or reusing pieces for other macros.

As far as the naming goes, you can split up the name into two pieces and put them back together after incrementing. I’m away from my Mac, but I can provide an example if you don’t figure it out on your own. Lemme know.

1 Like

I see. Thank you… I have to be more open to this. Just reading the KM Wiki and it’s overwhelming.

I’m reading and searching Google but I can’t figure out how this splitting would work. I guess I have to use another “get file attribute” action in the same line as the “get base name” action. The dev says in another post in the forum that a file can be split up into three parts, a name, a number and an extension.
Aren’t you using the get base name action in your example? So what is the right term for an actual name? This confuses me.

I would be glad if you could provide an example if time allows it. I’m already learning and I understand what every part in your macro does. But I’m still thinking in a box and can’t figure things out alone I’m afraid.
Thank you so much.

The wiki is a terrific reference, but I found I had to develop a general understanding of things before I could process most of the wiki. The forum is fantastic for learning and asking questions. The combo of wiki+forum+getting my hands dirty is what works for me.

Here’s one way you could chop up the filename into the week number and everything that preceeds it, then increment the week number and reassemble info the new file name. I’m not great with regex, so there might be a better statement. I just cobbled this one together.

Starting with “weekly plan_school week 11.numbers” your local__Rename variable should be “weekly plan_school week 12” - let me know.

Once you get it working, you can go back streamline the various actions as needed.


@evanfuchs has already made a helpful reply: I agree with what he says. I have found that modifications of the basic, non-automated so to speak, naming and location strategies can help a lot. In some cases for me making any kind of renaming and moving unnecessary in the first place.

There is, if you open Keyboard Maestro editor and press cmmnd + 2, the macro library which does contain a ‘rename file’ macro ready made. I haven’t used it myself and likely it would need tweaking for your needs.

I would look, anyway, when in situations like this in the Keyboard Maestro forum, it is amazing what they have there really built by the wizards
I mention that as a general principle.

If I was renaming files all the time and moving them I don’t thik it is excessive to get Hazel anyway? It works well and you would support a really good developer.


I referred to my lesson plans as my Creative Writing.

I’m just throwing out ideas. Maybe one or two might be helpful.

I am curious as to why you split the files into three.

I use to get a wee bit mixed up by my labeling the week’s plans until I saw a colleague just assign them a simple progression of numbers. Something that simple made it easier for me.

(Couldn’t you make a stationery pad?)

At any rate, I took a totally different approach to the plans. The state of Illinois overhauled the curriculum one year. Fortunately we got the criteria ahead of time so I spent the entire summer writing up a database. (I probably used FileMaker Pro).

I devised pull-down menus, radio buttons for the objectives, strategies etc. and actually enjoyed doing that. So there went my summer but I was so glad I did it because I knew that it would be very time-consuming while I was teaching. I finished a week of plans in twenty minutes. Other teachers were spending night after night battling these plans after teaching all day long.

I offered to give my database to other teachers that taught at the same grade level (or I could have helped modify my database to fit their grade level). When I tried to explain they looked at me as if I were from Mars.

Anyway, a database might be helpful. I loved FileMaker Pro but it is quite costly. I borrowed it from the District. (If anyone knows a less costly database program, I’d be interested in knowing.)

I just bought Keyboard Maestro a couple of nights ago. I believe I use to use it several years ago and once you get going on the macros… well, it is nothing short of amazing.

I signed up for MacSparky’s Field Guide for Keyboard Maestro and I am learning and I will get better at it. (David is a fantastic teacher.)

One thing I caught on readily to in KM was when you “record” what you are doing. Then you can build from there, modify other macros to generate new ones.

I was bound and determined to get ONE macro going. When I did I made other ones.

I signed up for KM users group and there are some brilliant people (much like here… they are eager to help).


Thank you so much. I will try it today, this looks very promising. I’m a tinkerer… I’m not good at inventing stuff. I would’ve needed weeks to figure that out. But seeing your example I’m starting to figure stuff out. Amazing… :smile:

@TudorEynon Thank you, too. I’ve already signed up at the KM forums and automators talk forums, too. With this one I have to say the whole community is very nice and helpful.
And I’m still thinking about getting Hazel 5. I have bought Hazel 3 and 4 and I loved it but I found that I couldn’t find enough use cases for it. I’m already using KM for more stuff than I’ve ever done with Hazel. But in combination with KM, possibilities are exponential I guess. :smiley:

@Katie Thank you for sharing your thoughts. I’m from Austria. Our school system is… old. As are the rules around it. There are still so many teachers writing all their stuff by hand. I’m 40 years old and when I put my Macbook Air on my table some are looking at me as if I’m from another planet. You’re right, I could use simpler names and labels. But I have to have a monthly plan, a weekly plan and a daily plan. I have them all in the same folder because I can access them very fast, it’s just one click. I could sort them all into dedicated subfolders but I was never a folder kind of guy. I hate it when they get too deep because the overview is suffering. It doesn’t feel right.
The database idea is awesome, I’ve never even thought about it. But then, it would be overkill. Things are very oldschool but simple around here. But I will definitively look into it. Thank you!


Austria, wow! How old are your students? So giving teachers “busywork” is an international past time?

I took an International Education course and it was interesting. I visited a school down in Mexico. The staff and kids were awesome. But they must have had 45 or 50 kids (all boys is what I observed) in a class.

I use to own Hazel and it is an awesome program. As I recall, it was very good at automating and putting things away so you didn’t have to work on it.

“Work smarter not harder” is my motto- something I think Apple does exceedingly well…


Right on. Happy tinkering!


My students are between 6 and 15 years old. I’m called a mobile teacher. I teach “German as a second language”, so I teach kids that immigrated to Austria. I just teach in small groups and drive from school to school so at least I’m not in an overcrowded class. It’s very rewarding and I love my job but administration gets more and more complicated and often I spend more time doing stuff like writing lists and plans than for lesson preparations. Our school system originated more than 100 years ago and didn’t change that much although we know from studies in the 70s that a lot is wrong. Like elementary school: starts at 7:45 am and ends at 11:20 am or 12:20 pm. This is from a time when every mother was at home.
Attempts to make school like it is in other countries like Norway are half baked at best.

This is why I’ve started to look into automation. To spend more time with important stuff. Like preparations and with my family. :slight_smile:


I’d do it this way without need for any added software but using shell script (inside a Terminal command). Shell scripts been around a long time.

# save this file into the folder where the numbers files are located
# suggested name "archivewsp.cmd"
# edit the archive folder name (changing to YOURUSERID to your actual userid)
# run terminal and change with "cd xx" command to that folder (xx here, no quotes)
# make file executable with "chmod 0770 archivewsp.cmd" (without quotes)
# then each week run terminal and run the command "./archivewsp.cmd" (without quotes)

# file extension
# base file name
wp="weekly plan_school week "
# archive folder
echo "What is current week number?"
read cw
echo "What is new week number?"
read nw
# do a verbose copy (-v) without overwritng existing file (-n)
cp -vn "$wp$cw$ext" "$af"

# rename with verbose (-v) without overwriting existing file (-n)
mv -vn "$wp$cw$ext" "$af$wp$nw$ext"
echo Archived $wp$cw$ext to $af and created here $wp$nw$ext

Your computer also has AppleScript and Python (and probably more) resources freely available for you to use.

Caveat Emptor.