Skip to content

Instantly share code, notes, and snippets.

@bashbunni
Created October 27, 2022 21:41
Show Gist options
  • Save bashbunni/f6b04fc4703903a71ce9f70c58345106 to your computer and use it in GitHub Desktop.
Save bashbunni/f6b04fc4703903a71ce9f70c58345106 to your computer and use it in GitHub Desktop.
CLI Pomodoro for Mac
# I'll be doing another one for Linux, but this one will give you
# a pop up notification and sound alert (using the built-in sounds for macOS)
# Requires https://github.com/caarlos0/timer to be installed
# Mac setup for pomo
alias work="timer 60m && terminal-notifier -message 'Pomodoro'\
-title 'Work Timer is up! Take a Break 😊'\
-appIcon '~/Pictures/pumpkin.png'\
-sound Crystal"
alias rest="timer 10m && terminal-notifier -message 'Pomodoro'\
-title 'Break is over! Get back to work 😬'\
-appIcon '~/Pictures/pumpkin.png'\
-sound Crystal"
@tymof1j
Copy link

tymof1j commented Jan 16, 2023

I'm getting an error zsh: command not found: timer(( I'm thinking that some package is missing but couldn't find one

@bassamsdata
Copy link

I'm getting an error zsh: command not found: timer(( I'm thinking that some package is missing but couldn't find one

she mentioned that you need to install https://github.com/caarlos0/timer. if you have brew you can via brew install caarlos0/tap/timer

@heygema
Copy link

heygema commented Jan 17, 2023

πŸ₯«

@Nykzom
Copy link

Nykzom commented Jan 18, 2023

Hey where can i save this code, so that i dont have to paste it in the terminal when im closing it, or do you just execute the file?

@dolanor
Copy link

dolanor commented Jan 18, 2023

You put it in your $HOME/.zshrc

@scotthaleen
Copy link

https://github.com/caarlos0/timer#install

brew install caarlos0/tap/timer

@bassamsdata
Copy link

if you have brew you can via brew install caarlos0/tap/timer

@AD0791 through taps in brew like above. If you wanna read more before installing it, it's on GitHub.

@cshintov
Copy link

cshintov commented Jan 19, 2023 via email

@jjsquady
Copy link

osascript -e 'display notification "β˜•" with title "Work Timer is up!" subtitle "Take a Break 😊" sound name "Crystal"'

πŸ‘πŸ»

@Nykzom
Copy link

Nykzom commented Jan 23, 2023

hey my app icon is always not correct. i put an png in my Picture dictonery and named it 'pumpkin.png'. Has anyone a fix?

@edrdesigner
Copy link

Nice

@ernstakavov
Copy link

Can someone please explain how exactly to run it. I couldn't figure it out :/

@Nykzom
Copy link

Nykzom commented Jan 25, 2023

Can someone please explain how exactly to run it. I couldn't figure it out :/

Hey.

Lets say u didnt install homebrew.
So just google homebrew mac. After installing it then just run the following commands

brew install caarlos0/tap/timer

brew install terminal-notifier

I installed oh-my-zsh. You cann install it too per:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

so after this open a terminal and type in "pwd"
you should be in '/Users/{YourPcName}

next command is 'ls -a' (you dont have to do that but you can see als hiden files)
now you can check if a '.zshrc' file exits.

now you can use an Editor to open this file, chose nano if your beginner or install vscode and use it:

  1. nano .zshrc
    copy the code above from bashbunni and STRG-V it at the end of the file.
    edit as needed (custom times for work and break)
    use the commands to save and exit

  2. vi .zshrc
    move to the end of the file.
    now press a to get in 'append-mode' then press enter to make space.
    STRG-V the code in πŸ˜†
    edit as needed (custom times for work and break)
    press ESC to go back in 'Normal mode"
    if you panic ':q' for abort mission in vim
    then press SHIFT-Z-Z (Shift and to times Z) -> to safe and Exit the File

  3. code .zshrc (i dont know, but i think this is if you have installed vscode)
    scroll down, paste the code in, edit as needed (custom times for work and break), press safe

now you should use work and break, and it should be working.. πŸ˜†
also you can close the terminal open a new one and it also should work again.

if you want to change the times for work and break or the alis just open terminal ->
check with 'pwd' where you are and start edit the .zshrc file with nano, vi(m) or (vs)code πŸ˜„

go to your settings at your mac and set notifications on for the terminal-notifier!

Hope i could help!

oh and bashbunni set the alias to work and break. if you just installed the timer you can set a timer by
'timer {number}[s or m} -n {title}'
for example 'timer 45min -n math study'

if you just type work it will run with the time and name in the config.
so default would be if you copy the code: 60min

so jo dont need to write every time: timer 60m -n work
Feel free to create your own alias πŸ˜†

@nayakayp
Copy link

This is great! How can I make this auto start work and auto start rest?

I test using this code.
When I run work command, the terminal auto execute rest command. But after the rest timer is up, the work command isn't execute. Vice versa when I run rest command first.

alias work="timer 5s && terminal-notifier -message 'Timer is up! Take a
Break' && rest
-title 'Work Timer is up! Take a Break 😊'
-appIcon '~/Pictures/tomato.png'
-sound Crystal"

alias rest="timer 10s && terminal-notifier -message 'Break is over! Get
back to work' && work
-title 'Break is over! Get back to work 😬'
-appIcon '~/Pictures/tomato.png'
-sound Crystal"

@MarcHurst
Copy link

Using that, if you use rest, it does that, then work, then dies out with the same error. I'm guessing something's preventing it from infinite looping (but couldn't tell you what)

@Nykzom
Copy link

Nykzom commented Jan 26, 2023

This is great! How can I make this auto start work and auto start rest?

I test using this code. When I run work command, the terminal auto execute rest command. But after the rest timer is up, the work command isn't execute. Vice versa when I run rest command first.

alias work="timer 5s && terminal-notifier -message 'Timer is up! Take a Break' && rest -title 'Work Timer is up! Take a Break 😊' -appIcon '~/Pictures/tomato.png' -sound Crystal"

alias rest="timer 10s && terminal-notifier -message 'Break is over! Get back to work' && work -title 'Break is over! Get back to work 😬' -appIcon '~/Pictures/tomato.png' -sound Crystal"

Hey i just made a function:

pomo(){
        echo "How many rounds you want to do?"
        read count;
        for i in {1..$count};
        do
                work;
                sleep 1;
                rest;
        done
}

hope it solves your problem. just type the function name in the terminal: here -> pomo
Oh, and put the code under the two alias!

*Thanks at @nayakayp for finding the lost bracket πŸ˜†

@nayakayp
Copy link

nayakayp commented Jan 27, 2023

This is great! How can I make this auto start work and auto start rest?
I test using this code. When I run work command, the terminal auto execute rest command. But after the rest timer is up, the work command isn't execute. Vice versa when I run rest command first.
alias work="timer 5s && terminal-notifier -message 'Timer is up! Take a Break' && rest -title 'Work Timer is up! Take a Break 😊' -appIcon '/Pictures/tomato.png' -sound Crystal"
alias rest="timer 10s && terminal-notifier -message 'Break is over! Get back to work' && work -title 'Break is over! Get back to work 😬' -appIcon '
/Pictures/tomato.png' -sound Crystal"

Hey i just made a function:

pomo(){
        echo "How many rounds you want to do?"
        read count;
        for i in {1..$count};
        do
                work;
                sleep 1;
                rest;
        done

hope it solves your problem. just type the function name in the terminal: here -> pomo Oh, and put the code under the two alias!

It worked!
Can you edit the code because it needs a closing bracket. Maybe others will face the problem if you don't edit it

Thank You!

@burhanorkun
Copy link

I like this configuration πŸ‘ try it

firstly install tool

brew install terminal-notifier
brew install caarlos0/tap/timer

Mac setup for pomodoro

add alias in your ".zshrc" file

alias work="timer 60m && say 'Mola verme zamanı dostum! Kalk ve biraz yürüyüşe çık! Biraz su iç!' \
                && terminal-notifier -message 'Pomodoro'\
        -title 'Work Timer is up! Take a Break 😊'\
        -appIcon 'http://vjeantet.fr/images/logo.png' \
        -sound Crystal"

alias rest="timer 10m && say 'Mola bitti, hadi ders çalışma zamanı' \
                && terminal-notifier -message 'Pomodoro'\
        -title 'Break is over! Get back to work 😬'\
        -appIcon 'http://vjeantet.fr/images/logo.png' \
        -sound Crystal"

then call on your terminal like "work" or "rest"

@nathan-hyan
Copy link

This is great! How can I make this auto start work and auto start rest?
I test using this code. When I run work command, the terminal auto execute rest command. But after the rest timer is up, the work command isn't execute. Vice versa when I run rest command first.
alias work="timer 5s && terminal-notifier -message 'Timer is up! Take a Break' && rest -title 'Work Timer is up! Take a Break 😊' -appIcon '/Pictures/tomato.png' -sound Crystal"
alias rest="timer 10s && terminal-notifier -message 'Break is over! Get back to work' && work -title 'Break is over! Get back to work 😬' -appIcon '
/Pictures/tomato.png' -sound Crystal"

Hey i just made a function:

pomo(){
        echo "How many rounds you want to do?"
        read count;
        for i in {1..$count};
        do
                work;
                sleep 1;
                rest;
        done
}

hope it solves your problem. just type the function name in the terminal: here -> pomo Oh, and put the code under the two alias!

*Thanks at @nayakayp for finding the lost bracket πŸ˜†

Thank you so much for this, it's just what I needed!

@kimmy2611
Copy link

I managed to get the script working, but at the end of the timer, the notification does not show up. I've installed the terminal-notifier using homebrew, but it doesn't appear to be show up. The timer just counts down and displays "finished" on the terminal. Any suggestions on how to fix this?

@bashbunni
Copy link
Author

@kimmy2611 go to Systems Preferences > Notifications > then make sure that terminal-notifier is allowed to send notifications with sounds, banners, etc

@kimmy2611
Copy link

@kimmy2611 go to Systems Preferences > Notifications > then make sure that terminal-notifier is allowed to send notifications with sounds, banners, etc

Oh I overlooked that! Thank you for the help!

@ben-hampson
Copy link

Also check that macOS is allowing terminal-notifier to run. At first when I ran terminal-notifier from iTerm 2, it wouldn't create notifications. I'm not sure exactly how I got it to show notifications but I think I first got it to run in Terminal, and then notifications worked when I ran the command from iTerm 2.

@griffeth
Copy link

griffeth commented Oct 4, 2023

@kimmy2611 go to Systems Preferences > Notifications > then make sure that terminal-notifier is allowed to send notifications with sounds, banners, etc

I'm running into the same problem but I have checked that Notifications have been enabled for terminal-notifier...anything else that could be causing this?
Screenshot 2023-10-04 at 11 44 01 AM

@hey-laura
Copy link

@kimmy2611 go to Systems Preferences > Notifications > then make sure that terminal-notifier is allowed to send notifications with sounds, banners, etc

I'm running into the same problem but I have checked that Notifications have been enabled for terminal-notifier...anything else that could be causing this? Screenshot 2023-10-04 at 11 44 01 AM

It's a mess. My weird fix was to install via brew (wasn't working correctly like yours even with Notifications enabled), download the binary from the repo and put the app in Applications - which triggered it to work. Then I brew uninstalled it, removed the app, and reinstalled again, now it works .... Made sure the Notifications are enabled after all that - macos might do a banner pop up for you to enable it.

@woolgathering
Copy link

Super helpful, thanks for posting this.

If it's helpful to anyone, I edited the alias to instead run as a bash script so we can turn on/off focus mode easily, including turning it off when exiting the program early. I also added a time arg but it defaults to whatever you time you write in the script (25m and 5m below):

#!/bin/bash

# Function for work mode
work() {
    local duration=${1:-25m}  # Default to 5 minutes if no argument is provided
    macos-focus-mode enable
    timer "$duration"
    macos-focus-mode disable
    osascript -e 'display notification "β˜•" with title "Work Timer is up!" subtitle "Take a Break 😊" sound name "Crystal"'
}

# Function for rest mode
rest() {
    local duration=${1:-5m}  # Default to 10 minutes if no argument is provided
    timer "$duration"
    osascript -e 'display notification "β˜•" with title "Break is over" subtitle "Back to work, loser δ·‘" sound name "Crystal"'
}

# Trap to disable focus mode when script exits
trap 'macos-focus-mode disable' EXIT

# Main script logic
case "$1" in
    work)
        work "$2"
        ;;
    rest)
        rest "$2"
        ;;
    *)
        echo "Usage: $0 {work|rest} [time]"
        exit 1
        ;;
esac

@umkl
Copy link

umkl commented Apr 8, 2024

You don't need to install terminal-notifier if you don't want to. You can trigger notifications on osx with applescript

osascript -e 'display notification "β˜•" with title "Work Timer is up!" subtitle "Take a Break 😊" sound name "Crystal"'

but how would i combine this with the alias, cause then there are 3 layers of strings?

@umkl
Copy link

umkl commented Apr 8, 2024

You don't need to install terminal-notifier if you don't want to. You can trigger notifications on osx with applescript

osascript -e 'display notification "β˜•" with title "Work Timer is up!" subtitle "Take a Break 😊" sound name "Crystal"'

but how would i combine this with the alias, cause then there are 3 layers of strings?

ok you would have to escape it like this: " -> so in the rc-file it would look like this:

alias work="timer 50m && osascript -e 'display notification \"β˜•\" with title \"Work Timer is up!\" subtitle \"Take a Break 😊\" sound name \"Crystal\"'"

@SmithWebDev
Copy link

i've been playing around and attempting to add a time input, but it doesnt recognize an argument. I've looked over my other alias and have no issues with adding an argument.

alias work="timer $1 && osascript -e 'display notification \"β˜•\" with title \"Work Timer is up!\" subtitle \"Take a Break 😊\" sound name \"Crystal\"' && say \"Phase complete\""

@umkl
Copy link

umkl commented Apr 9, 2024

i've been playing around and attempting to add a time input, but it doesnt recognize an argument. I've looked over my other alias and have no issues with adding an argument.

alias work="timer $1 && osascript -e 'display notification \"β˜•\" with title \"Work Timer is up!\" subtitle \"Take a Break 😊\" sound name \"Crystal\"' && say \"Phase complete\""

alias work='work_alias(){ timer "$1" && osascript -e "display notification \"β˜•\" with title \"Work Timer is up!\" subtitle \"Take a Break 😊\" sound name \"Crystal\"" && say "Phase complete"; unset -f work_alias; }; work_alias'

this works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment