A simple “look away for 20 seconds every 20 minutes” 20-20-20 eye care reminder in Waybar.

Sometimes I stare at the screen for too long, and forget to give my eyes a break. So I wrote this little bash script / waybar module to remind me to look away for 20 seconds every 20 minutes.

Warning every 20 minutes
Counting down after click

I uses 3 empty files in the /tmp/ folder to keep state. The tmp folder is deleted upon reboot, which resets the state and prevents it form showing the timer immediately on boot.

The Script (save this somewhere and make it executable via chmod -x scriptname.sh):

#!/bin/bash

START_TRIGGER="/tmp/sway_break_timer_start"
COUNT_START="/tmp/sway_break_timer_start_time"
FIRST_RUN="/tmp/break_timer_first_run"

# ---------------- FIRST RUN CHECK -------------------
if [[ ! -f $FIRST_RUN ]]; then
    # First execution after Waybar start → skip
    touch "$FIRST_RUN"
    echo "{\"text\":\"\"}"
    exit 0
fi

# ---------------- CLICKED → START COUNTDOWN -------------------
if [[ -f $START_TRIGGER ]]; then
    rm -f "$START_TRIGGER"
    date +%s > "$COUNT_START"
fi

# ---------------- COUNTDOWN MODE -------------------
if [[ -f $COUNT_START ]]; then
    START_TIME=$(cat "$COUNT_START")
    NOW=$(date +%s)
    ELAPSED=$(( NOW - START_TIME ))
    LEFT=$(( 20 - ELAPSED ))

    if (( LEFT <= 0 )); then
        rm -f "$COUNT_START"
        echo "{\"text\":\"\"}"
        exit 0
    fi

    # Output countdown
    echo "{\"text\": \"Look away: ${LEFT}s\", \"class\": \"countdown\"}"

    # Request next update
    pkill -RTMIN+20 waybar
    exit 0
fi

# ---------------- NORMAL MODE (every 1200 seconds) -------------------
echo "{\"text\": \"Look away: click to start\", \"class\": \"break\"}"
exit 0

Add it to your ~/.config/waybar/config.jsonc (change the scriptname.sh and path to where you saved the script)

// -------------------------------------------------------------------------
// Modules
// -------------------------------------------------------------------------

"custom/break_timer": {
  "exec": "/path/to/scriptname.sh",
  "interval": 1200,
  "return-type": "json",
  "signal": 20,
  "on-click": "touch /tmp/sway_break_timer_start"
}

and also in ~/.config/waybar/config.jsonc add it to a display location, for example:

"modules-center": ["custom/break_timer"],

I also added some CSS to style it, in ~/.config/waybar/style.css

@import "/usr/share/sway/templates/waybar/style.css";

.break {
  color: #ff8800;
  font-weight: bold;
}
.countdown {
  background-color: #ff8800;
  font-weight: bold;
  padding: 0 30px;
  color: @theme_base_color;
}

You can change the interval in the config.jsonc to the amount of seconds you want to be warned, “interval”: 1200, is 20 minutes.

Leave a Comment