Important
Follow the 20/20/20 Rule
Every 20 minutes of screen time, look at something 20 feet away for at least 20 seconds to reduce eye strain.
#!/bin/sh
while true; do
echo -e "\a" # ASCII bell character for beep sound
# Show the message for 1 minute with a countdown timer and reminder text
(
for i in $(seq 1 60); do
echo "# $((60 - i)) seconds remaining"
echo "$((i * 100 / 60))" # This updates the progress percentage
sleep 1
done
) | zenity --progress --title="Take a 20-second break and look 20 feet away!" --percentage=0 --auto-close &
# Wait a moment to ensure the Zenity window is open
sleep 1
echo -e "\a"
# Wait for 19 minutes (1140 seconds) before showing the message again
sleep 1140
done
Note
Notification Message
The script uses Zenity to display a pop-up message reminding you to follow the 20/20/20 rule:
"Take a 20-second break and look 20 feet away!"
Ensure Zenity is installed, as it is required to display the GUI pop-up.
- Ubuntu/Debian-based systems:
sudo apt update sudo apt install zenity
Tip
Use zenity to create pop-up notifications in Linux for eye strain reminders or other tasks. You can easily customize the script for other notifications too.
-
Create the script file:
sudo nano /usr/local/bin/notify.sh
-
Paste the contents of the script (from above) into the file.
-
Make the script executable:
sudo chmod +x /usr/local/bin/notify.sh
Now, let's create a systemd user service to run this script at startup.
-
Create a directory for user
systemdservices (if it doesn't exist already):mkdir -p ~/.config/systemd/user/ -
Create a new
systemdservice file:nano ~/.config/systemd/user/eye-reminder.service -
Add the following content to the service file:
[Unit]
Description=Eye care reminder
After=graphical.target
[Service]
Type=simple
ExecStart=/bin/bash /usr/local/bin/notify.sh
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/YOUR_USER/.Xauthority
Restart=always
[Install]
WantedBy=default.targetReplace YOUR_USER with your actual username.
Warning
The script uses Zenity, which requires a GUI to display pop-up notifications. Ensure your system starts a graphical session at boot, and the service starts after the GUI is up (After=graphical.target).
Enable and start the service in user mode so that it runs automatically on system boot.
# Enable the service
systemctl --user enable eye-reminder.service
# Start the service immediately
systemctl --user start eye-reminder.serviceImportant
Testing the Service
After starting the service, test if the reminder pop-up appears. If it does not, verify that DISPLAY=:0 is correct for your session. You can check it with:
echo $DISPLAYTo verify if the service is running:
systemctl --user status eye-reminder.serviceCaution
If the pop-up notifications are not working, ensure that your user session is correctly set up and that the service is configured to run under your user's environment.
Tip
You can adjust the sleep duration in the script (sleep 1140) to modify how often the reminder appears. By default, it shows every 19 minutes.
Warning
Frequent pop-ups may interfere with your workflow. Adjust the reminder intervals as needed to suit your work habits.
Note
If you want to stop or disable the reminder in the future, use the following commands:
- To stop:
systemctl --user stop eye-reminder.service - To disable:
systemctl --user disable eye-reminder.service --now