- Published on
This Bash Script Reminds Me to Take Breaks (And Saves My Back)
💡 The Problem: Coding Tunnel Vision
So here’s the deal: I love what I do. I’m a developer, which means I spend hours deep in code—debugging, refactoring, tweaking little things for that dopamine hit of a clean build.
But that same focus is a curse. I’ll sit in the same chair, hunched over, hands glued to my keyboard, for hours. No breaks. No stretches. Not even water sometimes (oops).
Then my neck starts acting up, my back gets stiff, and I start wondering why I feel like I’m 80.
🧠 The Spark: Automate the Nagging
I knew I should be taking breaks. I’d read enough about the Pomodoro technique, RSI prevention, and all that. But I just kept forgetting. So I did what any automation-loving dev would do:
I wrote a Bash script to remind me.
Just a friendly popup every 45 minutes that says, “Yo, stretch a bit.” Minimal. Effective. And surprisingly helpful.
🔧 The Setup: What This Bash Script Does
Here’s what I wanted it to do:
• Run silently in the background.
• Every 45 minutes, show a desktop notification (with sound if possible).
• Be easy to start and stop.
• Work on Linux and macOS (I mainly use both depending on the project).
Nothing fancy. Just enough to give Future Me a little nudge.
🖥️ The Script
Here’s the script I cooked up:
#!/bin/bash
# Duration between breaks in seconds (45 minutes)
BREAK_INTERVAL=$((45 * 60))
MESSAGE="Time for a break! Stretch, hydrate, look away from the screen 👀"
while true; do
sleep $BREAK_INTERVAL
# Show notification (macOS)
if [[ "$OSTYPE" == "darwin"* ]]; then
osascript -e "display notification \"$MESSAGE\" with title \"Break Reminder\" sound name \"Submarine\""
# Show notification (Linux - notify-send)
elif command -v notify-send &> /dev/null; then
notify-send "Break Reminder" "$MESSAGE"
else
echo "$MESSAGE"
fi
done
🧪 How It Works
• It runs an infinite loop with a sleep of 45 minutes between each iteration.
• After waking up, it checks the OS:
• On macOS, it uses osascript to fire a native notification (with a sound).
• On Linux, it uses notify-send.
• If nothing else works, it just prints to terminal (still better than nothing!).
🏁 How I Run It
I usually start it like this:
nohup ./break_reminder.sh &> /dev/null &
That sends it to the background silently, so I can just forget about it. To stop it:
ps aux | grep break_reminder.sh
kill <PID>
Or, you know, add a little wrapper function to your .bashrc or .zshrc for start/stop convenience.
😅 Small Gotchas
• On macOS, you might get sick of the default sound. You can customize the sound name to something more chill (like "Glass" or "Ping").
• If you close your terminal and didn’t run it with nohup, the script dies too. Learned that one the hard way.
• Linux users need to have libnotify / notify-send installed.
🙌 The Result: My Neck Thanks Me
I’ve been using this little script for months now, and genuinely—it helps. I actually stand up. I stretch. Sometimes I even go walk around the house or do 10 pushups.
It’s not some gamified productivity app or fancy habit tracker. But it’s just enough friction to break my flow before it gets physically painful.
And because it’s a script I wrote myself, I feel slightly more inclined to actually listen to it 😅
🔭 Looking Ahead: Making It Fancier?
Of course, there are ways to level it up:
• Add Pomodoro-style timers with work/break intervals.
• Let it auto-pause when Zoom/Meet or Slack Huddle is active (via AppleScript or DBus).
• Make it a macOS menu bar app using Swift or Electron.
• Log how many breaks I actually take (for data nerd points).
But honestly? For now, it works. And that’s the point.
Stay healthy, and happy hacking!