July 22, 2024

/ ~

Setup sound notification when bash command is done

When I run a command that takes a long time, I realize too late that it’s completed while I’m doing other things. That’s why I created an audible notify system using the script below.

Terminal window
npm install && say "npm install done"

If you want to add a tiny sound before the voice, you can use the afplay command.

Terminal window
npm install && afplay /System/Library/Sounds/Funk.aiff && say "npm install done"

You can convert this script into an alias.

Terminal window
notify() {
local message=$1
shift
local command="$@"
eval "$command" && afplay /System/Library/Sounds/Funk.aiff && say "$message"
}

You can now use it below:

Terminal window
notify "npm install done" "npm install"

Notes

  • You can list voices using the say -v \? command. For example, I can use Yelda voice for texts in Turkish.
    Terminal window
    say -v Yelda "Selamlar"