The reason it doesn't beep is that \a
(or ^G
) is the terminal bell code; it's up to the program handling stdout to turn that into a sound. Terminal.app will play a sound (unless you configure it to do "visual bell" instead, of turn it off entirely), but Idle will not. And, of course, if you're running without a tty, you get nothing.
If you don't mind using PyObjC (which comes pre-installed with the Apple-installed Pythons on all recent versions of OS X):
import Cocoa
Cocoa.NSBeep()
Of course this plays the OS X system beep, not the Terminal bell. Besides possibly being a different sound, this means if you disable the bell in Terminal, your script will still beep. (If you really want a Terminal bell, you can always script Terminal via, e.g., ScriptingBridge. But I don't think you care.)