r/MacOS27 • u/Rare_Pin9932 • 16m ago
Claude-generated Watchdog tool to "fix" Mail app freezing on Golden Gate
MODS: OK, I hope this post doesn't get removed, as I think it's useful. I'm describing the tool in this post, but have not attached it, just in case that's against the rules. I'm hoping that this means the post will not be removed. Someone can then tell me whether it's OK to post the tool, and I can upload the zip with instructions on how to install.
Also, I posted this on the general MacOS sub-reddit as well.
Anyway, both me and my paralegal have had problems with Mail app freezing since upgrading to Golden Gate. We're both on 27.2.1. Her Mail app freezes 3-4 times a day; mine is more like 1-2 times a day.
I had Claude do some digging, and while it couldn't provide a solution (I'm hoping 27.3 fixes this issue), it did detect when the problem occurred: the number of stuck threads in Mail app started going crazy:

So I asked Claude to write a Watchdog tool to monitor stuck threads on Mail app. It gave me a bash script that runs every 5 minutes (details: as a launch agent, using tools built into MacOS already, and needing no admin rights).
What the tool does:
About halfway to the limit where a crash is going to occur, and you're at your Mac (you've provided input in the last 2 minutes): a dialog pops up with Restart Mail and Later options:

It waits until you pause typing before showing the dialog. "Later" means it won't ask again for 30 minutes, unless Mail gets close to the limit of freezing.
However, if you've been away from your Mac (more than 2 minutes without input), it'll restart Mail -- including when the box popped up and nobody answered. The tool never restarts Mail on its own more than once an hour.
To restart Mail, the tool asks Mail to quit and save drafts. If Mail is already frozen, it force-quits it. Then it reopens Mail in the background and posts a notification:

Not the best solution, but better than no solution at all. Again, I'm more than happy to provide the zip and installation instructions if that's permitted.
Some interesting background: her Mac is an M5 MBA that I got when I hired her over the summer; she doesn't have much on her Mac, and her mailbox isn't that big. By comparison, my Mac is an M3 MBA, I have tons on my Mac, and my mailbox is 150,000+ messages. I've upgraded my Mac every 2-4 years for the last 25 years, and never do a fresh install.
So whatever the problem is, it's not related to how much cruft you have on your Mac (I have a lot; she does not), nor how big your mailbox is.