Little Girl's Mostly Linux Blog

EggTimer

Egg Timer

This page was last updated on October 12, 2013.

Method 1

This is a command line method for creating a timer using the sleep command. The system bell will sound once at the beginning and once at the end of the count.

  • Open a terminal window and type this command, replacing NUMBER with the number of seconds you’d like the timer to run:

    echo -e '\a' >&2; sleep NUMBER; echo -e '\a' >&2
    • For example, you would use this command to set a timer for 30 seconds:

      echo -e '\a' >&2; sleep 30; echo -e '\a' >&2
  • To time minutes, hours, or days with this command, you need to add an m for minutes, an h for hours or a d for days after the NUMBER in the command.
    • For example, you would use this command to set a timer for 30 minutes:

      echo -e '\a' >&2; sleep 30m; echo -e '\a' >&2

Method 2

This is a script that asks how long you’d like the timer to run, notifies you of each minute that passes and rings the system bell when the time is up.

  • The script:

    #!/bin/bash
    echo -n "How many minutes would you like the timer to run? "
    read limit
    echo
    echo "Timing $limit minutes..."
    echo
    counter=0
    while [ $counter != $limit ]; do
       echo "$counter minutes so far...";
       sleep 60
       let "counter = $counter + 1"
    done
    if [ $counter = $limit ]; then
       echo
       echo "Time's up - $counter minutes have elapsed!"
       echo -e '\a' >&2
       exit 0
    fi
    
  • Save the script:

    1. Copy the above script.
    2. Paste it into a text editor.
    3. Save the file as timer.sh.

  • Run the script:

    1. Open a terminal window.
    2. Change to the directory the script is in.
    3. Type this command:

      bash timer.sh
    4. Press the Enter key.

  • What it looks like when it runs:

    How many minutes would you like the timer to run? 3
    
    Timing 3 minutes...
    
    0 minutes so far...
    1 minutes so far...
    2 minutes so far...
    
    Time's up - 3 minutes have elapsed!
    

Alternative to system beep

If the system beep doesn’t work for you (mine currently doesn’t, and that could be that I didn’t wire my motherboard correctly or that Kubuntu no longer uses the same command(s) to trigger the beep), you can replace echo -e ‘\a’ >&2 with paplay /path/to/soundfile.ogg or paplay /path/to/soundfile.wav (replacing the path and file name with your path and file name) to use the PulseAudio sound player in the commands and scripts above.

Obligatory Happy Ending

And they all lived happily ever after. The end.

12 Comments »

  1. […] The shell script is actually a modified version of the one published here (https://mostlylinux.wordpress.com/commandline/eggtimer/). […]

    Pingback by Simple egg timer on Linux for Pomodoro technique « {love to code?} — December 19, 2010 @ 2:27 am

  2. Thanks been looking everywhere for a simple timer script/app for linux and there is NOTHING. Never thought of using bash and sleep() :( gj

    Comment by rocksonwater — February 8, 2013 @ 4:41 pm

    • I had trouble finding a simple timer program or widget, too. Thank goodness for scripts! (:

      Comment by mostlylinux — June 2, 2013 @ 8:25 am

      • Your wish is my command:

        http://xyne.archlinux.ca/projects/pystopwatch/

        Please add a small bio to this wonderful website.

        Comment by Dave — July 2, 2013 @ 3:13 am

        • I’d love to, but I get this:

          $ python PKGBUILD
            File "PKGBUILD", line 3
              pkgver=2012.12.24.1
                              ^
          SyntaxError: invalid syntax
          

          and this:

          $ python pystopwatch.install
            File "pystopwatch.install", line 1
              post_install() {
                             ^
          SyntaxError: invalid syntax
          

          when I try to run it. I’m probably doing something very obvious wrong and will probably slam my head against a wall when I realize what it was, but so far that’s as far as I’ve gotten. (:

          Comment by mostlylinux — July 2, 2013 @ 9:36 pm

  3. When you save the script, if you also grant the execute permission (eg chmod 755 timer.sh) then you may run the script without having to type ‘bash’ every time in front of it. Instead you can just type ‘./timer.sh’.

    Comment by Ryan — November 8, 2013 @ 11:28 pm

    • Good point! And for anyone who’s reading along and doesn’t know about the chmod command, if you do chmod 755 timer.sh in a terminal window in the directory the timer file is in, it will set the permissions of the file so that Owner has read, write, and execute permission, and Group and Others have read and execute permission, but not write permission.

      Comment by mostlylinux — November 9, 2013 @ 12:30 am

  4. To save typing, you can also echo the number of minutes into the script.

    For 10 minutes:

    echo 10 | ./timer.sh

    Comment by David Regal — February 12, 2015 @ 2:43 pm

    • I didn’t fully explain how this saves typing. After the timer is done, all I need to do in a bash prompt with command history is push up arrow and enter to run to the 10 minute timer again.

      Comment by David Regal — February 12, 2015 @ 2:48 pm

      • Nice! Interestingly, though, I got “bash: ./timer.sh: Permission denied” when I tried it in Kubuntu, but this works fine for me:

        echo 10 | bash timer.sh

        Comment by mostlylinux — February 12, 2015 @ 10:41 pm

        • You forgot to “chmod +x timer.sh”

          Comment by cb88 — February 17, 2015 @ 12:44 pm

          • [kicking self in head] That did it! Working like a charm. (:

            Comment by mostlylinux — February 17, 2015 @ 7:02 pm


RSS feed for comments on this post. TrackBack URI

Comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: