How to repeat the same edit many times on Mac
You can do this with Note My. Record the change once, replay it as many times as you need, watch it happen, and take the whole run back with a single undo.
Some edits are too specific for find and replace. You go to the start of a line, jump two words in, wrap something in quotes, add a comma at the end, move down. A regular expression could probably express it, but working the expression out takes longer than doing the edit by hand — except there are four hundred lines to do.
This is what macro recording is for. You perform the edit once, slowly and carefully, while Note My watches. Then you tell it how many times to do the same thing, and it does. The whole run counts as a single undo, so a macro that turns out to be subtly wrong costs you one keystroke rather than an afternoon of repair.
Recording and playback happen entirely on your Mac. Nothing about the file or the macro is uploaded, there is no account to create, and your work never leaves the machine.
Record the edit once
-
Put the caret where the edit begins
A macro replays your movements, so it needs to start from the same relative place every time — usually the beginning of a line.
-
Start recording
Press ⌥⌘R for Macro ▸ Start Recording, or use the Macros pull-down in the toolbar. A glass pill appears at the top of the window with a pulsing red dot, the words Recording Macro and a running action count, and the toolbar glyph flips to a red stop symbol. The pill is a preference — on by default, switchable in Settings ▸ Macros — while the glyph always changes, so there is a cue either way.
-
Make the edit, using the keyboard
Typing, deleting, pasting, selecting, arrow and word movement, home and end, Return and Tab are all captured. So are find next and previous, a single replace, Go to Line, saving, encoding and line-ending conversion, bookmark toggles and tab renames.
Watch the action count in the pill: short macros are easier to trust than long ones. You always know what went into the recording, because our macro recorder speaks up at the time — a beep and the message "That action can't be recorded." — so what you saw it take is exactly what plays back later.
-
Stop, and decide whether to keep it
Press ⌥⇧⌘R for Macro ▸ Stop Recording. A brief message confirms how many actions were recorded, then a sheet asks whether to save this macro, with Save, Don't Save and Cancel. Saving it gives it a name and puts it in Macro ▸ Manage Macros… for later. Not saving keeps it available for the current session.
Replay it
Both playback commands lead to the same sheet, titled Replay Macro. It has two tiles — Current Tab and All Open Tabs — a repeat stepper, and Run and Cancel buttons. ↩ runs, ⎋ cancels.
The difference between the two menu items is only what the stepper starts at:
| Command | Shortcut | Stepper starts at |
|---|---|---|
| Macro ▸ Playback | ⌥⌘P | 1 |
| Macro ▸ Playback Multiple Times… | — | 5 |
The stepper accepts anything from 1 to 9,999. Above 50 repeats you get a confirmation sheet before anything runs — a deliberate speed bump, because 5,000 is two keystrokes away from 50 on a stepper.
Choosing All Open Tabs works through your open tabs in the order they sit in the tab bar, bringing each one to the front as it goes. Closing a tab part-way through is safe — it is left out of the rest of the run rather than turning into an error.
Watching it run, and slowing it down
A run is something you watch. The edits land on screen one after another and you can follow them as they go, which is the point: a macro you can watch is a macro you can judge.
If it still goes past too quickly to follow, Settings ▸ Macros has a playback delay. You can set anything from 0 to 200 milliseconds per action, and it is 0 to begin with. Set it to 40 or 50 for the first run of a new macro, confirm it is doing what you meant, then put it back to 0 for the real work. A delay earns its keep whenever a wrong result would still look plausible — quoting, or bracket balancing.
Recording stays out of the way while a run is under way, so a macro never ends up recording itself as it plays.
One undo for the whole run
This is the fact that makes long runs safe to attempt. The entire playback — every iteration, every action, across every tab it touched — counts as one step, named Macro Playback in the Edit menu. A single ⌘Z reverses all of it. Press it the moment something looks wrong, before you make any other edit by hand.
Because the run is one undo, the cheapest way to test a macro is to run it for real. Set the repeat count high, look at the result, and press ⌘Z if it is wrong. There is nothing to reconstruct by hand.
Stopping a run in progress
Press ⎋ — Macro ▸ Cancel Playback. The run stops where it is. What has already been applied stays applied, and it is still part of the same single step, so one ⌘Z takes back everything the interrupted run did.
One run plays at a time, so a second macro never lands on top of one that is still going. Let the first finish, or press ⎋, and you can start the next straight away.
Awkward lines, and the report at the end
An action can fail on iteration 300 for ordinary reasons — the caret ran out of document, a find had no next match, a line number no longer exists. By default the failing action is skipped and the run carries on, which is usually what you want when a handful of lines are simply different. If you would rather it halted at the first problem, turn on stop-on-error in Settings ▸ Macros.
Either way you get a report sheet at the end: a summary glyph tinted by outcome, three chips reading Succeeded, Skipped and Failed, and a list of every non-success row with the tab it happened in and a plain-English reason. Only a stop-on-error abort counts as failed; everything else is a skip. A run that did nothing at all shows a brief message instead of a sheet.
Recipes: making the macro walk the file
A macro repeats an edit, and you decide where each repetition lands by recording the navigation as part of the edit itself. Three patterns do nearly all the work.
Move down one line at the end. The simplest and most robust: begin at the start of a line, do the edit, finish by moving to the start of the next line. Set the repeat count to the number of lines you want touched.
Find next as the step. Record a find next before the edit, so each iteration lands on the following occurrence of a pattern rather than the following line. This handles files where the interesting lines are scattered.
Bookmark first, then walk the bookmarks. Open Find and Replace from the toolbar, search for the pattern, and press Bookmark All — or use ⌥⌘B, Bookmark All Search Matches. Then record a macro that presses F2 for the next bookmark and makes the edit. Two related commands are worth knowing while you are there: Copy Bookmarked Lines and Delete Bookmarked Lines, which sometimes remove the need for a macro entirely.
⌘L — Go to Line — records too, and replays the exact number you typed on every iteration. That makes it the tidy way to open a macro on a known landmark: jump straight to the line where the interesting part of the file begins, then let one of the three patterns above walk on from there.
Troubleshooting
The macro drifts out of alignment after a few iterations
Almost always the recorded movement is relative to something the edit itself changed. Re-record it, and make the last recorded action an explicit move to the beginning of the next line rather than a sequence of arrow presses that assumes a line length. Run it five times first, look, then run it 500.
Knowing exactly which actions were captured
Our macro recorder covers typing and deletion, movement and selection, paste, find next and previous, single replace, Go to Line, save, encoding and line-ending conversion, bookmarks and tab rename — the ordinary keyboard work that most repetitive editing is made of. You find out as you record, not at playback: the message "That action can't be recorded." appears at the moment it matters and, unless you have switched the alert off in Settings ▸ Macros, a beep goes with it. The message is what carries the information; the sound is only an alert. When a job mixes one-off work with repetitive work, do the one-off part by hand first — settle the indentation with our indentation engine, say — and then record the part that repeats. Short recordings are the ones you can trust at four hundred iterations.
Running a macro I saved earlier
Saved macros wait for you in Macro ▸ Manage Macros…. The window lists them with Run, Run Multiple…, Rename and Delete, and a double-click on a row runs it there and then, so a macro you recorded last month is two clicks from doing its job again. ⌥⌘P always replays the current macro, which keeps the one you are actively working on a single keystroke away.
A macro that saves files reported a permission error
Give the folder your go-ahead once and the run goes straight through afterwards. Open the folder yourself and save a file into it with File ▸ Save As…; from then on a macro can write there as freely as you can. It is worth doing before a long run rather than in the middle of one. If a save does not land, ⌘Z still takes the whole run back in a single step, so you can settle the folder, put the caret back at the start and play the macro again from a clean sheet. Everything a macro writes stays on your Mac: nothing is uploaded, and there is no account involved.
The run finished but the report says everything was skipped
Usually the first action could not apply and every iteration failed the same way — a find with no matches, or a caret that started somewhere the macro did not expect. Press ⌘Z and run it again from the right position.
When a macro is the right tool
A macro plays back exactly what you did, in the order you did it, and that is the whole of its appeal. Nothing is inferred and nothing is guessed on your behalf: if you watched the edit land correctly once, you already know what four hundred repetitions will look like. Reach for one when the change is about position and sequence — start here, jump that far in, wrap this, add that, move down — the sort of edit that takes longer to describe than to perform.
When the change is about matching text instead, our find and replace is the quicker route, and the regular-expression option makes short work of anything with a shape to it. The two are at their best together: search for the pattern, press Bookmark All, then record a short macro that walks the bookmarks and does the part a pattern could not express. You get the reach of a search and the judgement of a hand edit in a single pass.
Scope is yours to set as well. A run can stay inside the tab in front of you, or sweep every tab you have open — so the way to handle a batch of files is to open them together, get the macro right in the first one, then choose All Open Tabs and let one run carry it through the lot in tab-bar order. With the whole thing sitting under a single undo, a wide run is a cheap experiment rather than a commitment, which is exactly the confidence you want before touching four hundred lines at once.
Frequently asked questions
How many times can I repeat a macro?
Between 1 and 9,999 in a single run. Above 50 repeats a confirmation sheet appears first, so a long run is always one you chose deliberately. Long macros replay as readily as short ones, and however many iterations you ask for, the whole run comes back with a single ⌘Z.
Can I undo an entire macro run in one step?
Yes. The whole run counts as one step, listed in the Edit menu as "Macro Playback", so a single ⌘Z reverses every iteration — including a run you cancelled part-way through.
How do I stop a macro that is already running?
Press ⎋, which is Macro ▸ Cancel Playback. Edits already made remain, as part of the same single step, so one undo still clears them.
Can one macro run change every open tab?
Yes — choose All Open Tabs in the Replay Macro sheet. Each tab is brought to the front in turn, in tab-bar order, and a tab you close part-way through is left out of the rest of the run.
Why is the playback too fast to see what it did?
The default playback delay is 0 milliseconds. Raise it in Settings ▸ Macros — the range is 0 to 200 milliseconds per action — then set it back.
Are saved macros kept between launches?
Yes. Save a macro when you stop recording, or later with Macro ▸ Save Current Macro…, and it stays in Macro ▸ Manage Macros… the next time you open the app, on your Mac and nowhere else. A macro you chose not to save lasts for the session only.