Skip to content

Instantly share code, notes, and snippets.

@letam
Created May 14, 2020 02:33

Revisions

  1. letam created this gist May 14, 2020.
    31 changes: 31 additions & 0 deletions zen-timer.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/usr/bin/env bash

    # Break Timer using Zenity (requires Linux and GTK)

    [[ $# != 1 ]] && >&2 echo "Usage: $0 MINUTES" && exit 1
    minutes=$1

    pyp() { python -c "print($1)"; }

    if grep -q '\.' <<<$minutes; then
    seconds=$(pyp "int($minutes*60)")
    else
    seconds=$((minutes*60))
    fi

    display_dimensions=$(xdpyinfo | awk '/dimensions/{print $2}')
    width=$(cut -f1 -dx <<< $display_dimensions)
    height=$(cut -f2 -dx <<< $display_dimensions)

    sleep $seconds && \
    zenity --timeout 15 --warning --text="Step away from the machine." --width $width --height $height


    exit


    ## References
    - [Pomodoro Timer for Linux](https://superuser.com/questions/224265/pomodoro-timer-for-linux/669811#669811)
    - [Bash, zenity progress bar without cancel](https://stackoverflow.com/questions/4907381/bash-zenity-progress-bar-without-cancel)
    - [Control the size of the content in a zenity window](https://stackoverflow.com/questions/18234920/control-the-size-of-the-content-in-a-zenity-window)
    - [How can I get the monitor resolution using the command line?](https://askubuntu.com/questions/584688/how-can-i-get-the-monitor-resolution-using-the-command-line)