Last active
July 1, 2025 21:33
-
-
Save lucasbracher/e8421e4575ce6ad84b404d0a85f20c70 to your computer and use it in GitHub Desktop.
Quick and simple audio pomodoro for MacOS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Usage: | |
| # ./audio_pomodoro_macos.sh <first_pomodoro_time> <number of pomodoros> | |
| # Example: | |
| # ./audio_pomodoro_macos.sh 20m 10 | |
| # It will create 10 pomodoros; first one is 20 minutes long, subsequent are 25 minutes long. | |
| # Both arguments are optional. If none are given, it will create 16 pomodoros, 25 minutes long each. | |
| # 16 pomodoros equals 8 hours: | |
| POMODORO_COUNT="${2:-16}" | |
| # Set a chime | |
| CHIME_FILENAME="copper-bell-ding-25-204990.mp3" | |
| # Pomodoro time equals 25 minutes | |
| POMODORO_TIME="${1:-25m}" | |
| play_chime () { | |
| if [ -f "$CHIME_FILENAME" ]; then afplay "$CHIME_FILENAME" &; fi | |
| } | |
| fade_in_and_chime () { | |
| for ((i=0; i<=$1; i++)); do osascript -e "set volume output volume $i"; done | |
| play_chime | |
| } | |
| fade_out_and_chime () { | |
| play_chime | |
| for ((i=$1; i>=0; i--)); do osascript -e "set volume output volume $i"; done | |
| } | |
| while [ $POMODORO_COUNT -gt 0 ] | |
| do | |
| echo Starting Pomodoro $POMODORO_COUNT... | |
| time sleep $POMODORO_TIME | |
| POMODORO_TIME=25m | |
| if [ $POMODORO_COUNT -gt 1 ] | |
| then | |
| # retrieve old volume: | |
| OLD_VOLUME="$(osascript -e "output volume of (get volume settings)")" | |
| fade_out_and_chime $OLD_VOLUME & | |
| time sleep 5m | |
| fade_in_and_chime $OLD_VOLUME & | |
| else | |
| sleep 5m | |
| fi | |
| POMODORO_COUNT=$(($POMODORO_COUNT - 1)) | |
| done | |
| afplay mixkit-happy-bells-notification-937.wav | |
| echo Done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment