I have a script running in the background and sends me an alert every few minutes. I want the alert to be in the form of a beep.
Question: How can I play a beep in mac terminal?
I have a script running in the background and sends me an alert every few minutes. I want the alert to be in the form of a beep.
Question: How can I play a beep in mac terminal?
printf \\a and osascript -e beep play the default alert sound, but they are silent if the alert volume is set to zero. printf \\a is also silent if an audible bell is disabled.
You could also use afplay or say:
afplay /System/Library/Sounds/Funk.aiff
say done
There are more sound effect files in /System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds/.
The simplest way is the use a bell
echo -e "\a"
-e is a non-POSIX extension supported by some shells, e.g., bash. Instead, prefer to use the portable printf command, e.g., printf '\a'. Still, the most portable solution is tput bel because the terminal may use something other than or in addition to Control-G.
– Chris Page
Aug 01 '22 at 18:44
Another way is to echo ^G. But you don't literally type the ^G. Instead, type ctrl+v, ctrl+g, which will appear as echo ^G.
ctrl+G by itself does not do anything for me on a mac.
– wisbucky
Feb 20 '18 at 19:52
Hear and pick
ls /System/Library/Sounds/ | awk '{print $1}' | while read sound; do printf "using $sound...\n"; afplay /System/Library/Sounds/$sound; sleep 0.5; done
ls /System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds/ | awk '{print $1}' | while read sound; do printf "using $sound...\n"; afplay /System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds/$sound; sleep 0.5; done
tput belworks in most shells.
From this answer on a related Stack Overflow question:
There's one more way that can be useful in cases like, let's say you forgot to set the alert and in the middle of the process, and on Iterm. Simply Cmd + Option + A while in terminal screen lets you have a notification in the end of the process.
say -v ?(in Yosemite, at least) to get a list of voices installed -- I had several! Here's a little script to say what you want in every available voice:for i in $(say -v \? | awk '{print $1;}'); do echo $i; say -v $i "Build terminated\!"; done– scorpiodawg Jan 27 '15 at 17:25say -v '?'with single quotes because of zsh. – Funktional Nov 12 '20 at 01:51