Spending hours staring at code can take a serious toll on your posture, eyes, and overall health. Standard alarm apps are often too intrusive or easily ignored. What if you could build a custom desktop notification system that gently reminds you to take a break without breaking your flow?
Today, we're going to build a simple but highly effective Productivity Reminder script using Python. This script will run quietly in the background and pop up native desktop notifications at specified intervals to remind you to stretch, drink water, or look at something 20 feet away. Best of all, we will implement logic to ensure it doesn't bother you outside of work hours.
The Science of the 20-20-20 Rule
Before we jump into the code, let's talk about why this matters. Digital Eye Strain is a real medical condition. Optometrists recommend the **20-20-20 rule**: every 20 minutes, look at something 20 feet away for at least 20 seconds. This simple habit prevents the eye muscles from "locking" into a near-focus state, reducing headaches and fatigue.
Our script isn't just a toy; it’s a health tool that automates the advice that doctors give but we usually forget in the heat of a debugging session.
Prerequisites: The plyer Library
To interact with the native desktop notifications on Windows, macOS, or Linux, we will use a fantastic cross-platform library called plyer. It acts as a bridge between Python and your OS’s notification center (Windows Toasts, macOS Notifier, or libnotify on Linux).
import time
import random
from datetime import datetime
from plyer import notification
# ⚙️ Configuration
INTERVAL = 1800 # 30 minutes in seconds
START_HOUR = 9 # Start at 9 AM
END_HOUR = 18 # Stop at 6 PM
REMINDERS = [
("Hydration Check 💧", "Time to drink a glass of water!"),
("Eye Rest 👁️", "Look at something 20 feet away for 20 seconds."),
("Posture Check 🧘", "Sit up straight and roll your shoulders back."),
("Stretch Time 🤸", "Stand up and stretch your legs for 1 minute.")
]
def is_working_hours():
now = datetime.now().hour
return START_HOUR <= now < END_HOUR
def send_notification(title, message):
try:
notification.notify(
title=title,
message=message,
app_name="Snapdo Health Bot",
timeout=15 # Stays on screen for 15 seconds
)
except Exception as e:
print(f"Notification Error: {e}")
if __name__ == "__main__":
print("🤖 Snapdo Health Bot is active and guarding your back.")
while True:
if is_working_hours():
title, message = random.choice(REMINDERS)
send_notification(title, message)
print(f"[{datetime.now().strftime('%H:%M')}] Reminder sent.")
time.sleep(INTERVAL)Advanced: Running Silently on Windows
If you're on Windows, you probably don't want a black command prompt window visible in your taskbar all day. Here is a trick: rename your file extension from .py to .pyw. This tells Windows to use pythonw.exe, which executes the script in the background without a console window. To stop it, you just find it in the Task Manager.
Adding Custom Icons
To make the bot feel truly "premium," you can add a custom icon. The notification.notify function accepts an app_icon parameter which should be the path to a .ico file (Windows) or .png (some Linux distros). Adding a small 32x32 pixel icon makes the notification look integrated into your professional workflow rather than a random script error.
Frequently Asked Questions
Does this work on M1/M2/M3 Macs?
Yes, plyer is compatible with Apple Silicon. However, ensure that you have given your terminal application permission to send notifications in macOS System Settings. If the script runs but nothing pops up, check "Notifications" and "Focus" settings.
Can I trigger sound with the notification?
plyer doesn't handle sound directly, but you can use the os module to play a sound file right before calling the notification. On Windows, import winsound is built-in and perfect for small beeps.
How do I make it start automatically when I turn on my computer?
On Windows, place a shortcut to your .pyw file in the shell:startup folder. On macOS, go to System Settings > General > Login Items and add your Bash script that calls the Python file. Automation only works if it doesn't require you to remember to turn it on!
"Your mind is your most valuable asset, but it runs on a biological machine. Maintain the machine, and the code will follow."
The Bottom Line
In less than 50 lines of code, you've created a custom health bot that integrates directly into your operating system. Programming isn't just about building enterprise software; it's also about creating small utilities that improve your daily life. By taking control of your notifications, you prevent burnout and create a more sustainable remote work environment. You can even extend this further by connecting it to your smart office lights, triggering a stretch playlist on Spotify, or sending automated Slack statuses when you step away for your 20-minute eye rest. Small automations compound over time, giving you significantly more energy at the end of the work day! Stay healthy, and happy coding!
Disclaimer: "All content is for educational use only. Snapdo and its authors are not liable for any financial losses, data loss, or hardware damage."