Skip to content

Instantly share code, notes, and snippets.

@MarkParker5
Last active July 8, 2024 20:07
Show Gist options
  • Save MarkParker5/e61fa22a8e23fca5c2b09d9ce543e183 to your computer and use it in GitHub Desktop.
Save MarkParker5/e61fa22a8e23fca5c2b09d9ce543e183 to your computer and use it in GitHub Desktop.
Oks - make a sound once a process is complete (macOS)
oks() { # like ok but with sounds, just append `; oks` to your command
s=$?
sound_ok=/System/Library/Sounds/Glass.aiff
sound_error=/System/Library/Sounds/Basso.aiff
if [[ $s = 0 ]]; then
echo -e "\033[0;32mOK\033[0m" # Green text OK
pid=$( afplay $sound_ok >/dev/null & echo $! ) # Play sound in bg and suppress any output
say "Done"
else
echo -e "\033[0;31mERROR: $s\033[0m" # Red text ERROR
pid=$( afplay $sound_error >/dev/null & echo $! ) # Play sound in bg and suppress any output
say "Error"
fi
}
# https://askubuntu.com/questions/277215/how-to-make-a-sound-once-a-process-is-complete
# https://stackoverflow.com/questions/24843614/execute-process-in-background-without-printing-done-and-get-pid
# https://superuser.com/questions/598783/play-sound-on-mac-terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment