122

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?

rk.
  • 1,345

6 Answers6

205

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/.

Ahmed Ashour
  • 2,490
Lri
  • 42,502
  • 8
  • 126
  • 159
27

The simplest way is the use a bell echo -e "\a"

demure
  • 6,550
12

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

8

tput bel works in most shells.

From this answer on a related Stack Overflow question:

Kenny Evitt
  • 453
  • 5
  • 16
7

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.

wisbucky
  • 3,346
1

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.

zx_
  • 21