$ cat notes/even-your-laptop-needs-a-coffee-sometimes.md

Even your laptop needs a coffee sometimes

· Used AIThis post was generated, edited or proofread using AI tools.

I’ve been training an image classifier on my underwater photos from dives. A classifier only learns from examples, so the work has three stages: collecting the photos, grading each one so the model knows what it shows, and then training on the graded set. Each stage is slow, and training alone can take hours. For most of that time the Mac was the thing getting in the way, dropping into sleep halfway through a run.

It turns out macOS has had the fix all along. caffeinate is a command-line tool, already on every Mac, that stops the machine from sleeping. I hadn’t come across it before, even though I’d been fighting the same problem.

The part that made it click is that it can wrap a command:

caffeinate -i python3 train.py

The Mac stays awake while train.py runs and is free to sleep as soon as it finishes. Nothing to remember to switch back on, and no battery drained overnight by a setting you forgot.

A few flags worth knowing:

  • -i stops the system going idle to sleep. This is what you get with no flags at all.
  • -d keeps the display on, useful if you want to watch progress.
  • -s stops system sleep, but only while on power.
  • -w <pid> waits for a process that’s already running, then lets go.

If you have a job that runs overnight, start it with caffeinate and go to bed. The next morning it’s done, and so is the Mac.