Home.

Pomodoro Timer Script for Mac

Finn Christiansen
Finn Christiansen

created at:

Why I Created This Script

Do you ever:

  • Want to be forced to take regular breaks?
  • Not want to pay for productivity apps?
  • Wish your computer would kick you out when your time is up?
  • Want your music to stop too, so you’re not distracted? Imagine getting locked out of your Mac and your music keeps playing—it defeats the purpose!

This simple Pomodoro timer script for Mac solves these problems!

Features

  • Uses 25 minutes as the default timer.
  • Accepts any number of minutes as input.
  • Displays the remaining time every second.
  • Unmutes the system at the start.
  • Mutes the system when time is up.
  • Stops Spotify from playing when the timer ends.
  • Locks your screen so you’ll need to re-enter your password.

The Script

function pomodoro() {
  # Default time is 25 minutes if no input is provided
  minutes=${1:-25}
  
  # Convert minutes to seconds
  total_seconds=$((minutes * 60))

  # Unmute system sound
  osascript -e "set volume without output muted"

  while [ $total_seconds -gt 0 ]; do
    # Calculate remaining minutes and seconds
    display_minutes=$((total_seconds / 60))
    display_seconds=$((total_seconds % 60))

    # Display the time in mm:ss format
    printf "\r%02d:%02d" $display_minutes $display_seconds

    # Wait for 1 second
    sleep 1

    # Decrease the remaining seconds
    total_seconds=$((total_seconds - 1))
  done

  echo ""
  echo "Time's up!"
  
  # Mute system sound and pause Spotify
  osascript -e "set volume with output muted"
  osascript -e 'tell application "Spotify" to pause'
  
  # Lock the screen
  osascript -e 'tell application "System Events" to keystroke "q" using {control down, command down}'
}

How to Use It

To start the standard 25-minute timer:

pomodoro

To start a custom timer (e.g., 7 minutes):

pomodoro 7

This is especially useful if you get interrupted and need a shorter session.

Lessons Learned

Sending the system-wide pause button event to the Mac without third-party software is tricky. It requires extra permissions that aren't ideal for this lightweight script.