brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: afplay plays a sound file from the terminal when a long job ends

Terminal
~/tips/tip-macos-afplay-sound-when-job-done

afplay /System/Library/Sounds/Glass.aiff

Plays an audio file through the default output, so a long command can tell you it has finished.

Long commands and a second window with something more interesting in it do not mix. Letting the Mac make a sound at the end solves that.

afplay /System/Library/Sounds/Glass.aiff

Per the man page, afplay plays an audio file to the default audio output. The built-in alert sounds live in /System/Library/Sounds, as AIFF files with names like Glass, Ping, Funk and Basso, and ls on that folder shows what your version has.

Put it behind the job you are waiting for:

./backup.sh; afplay /System/Library/Sounds/Glass.aiff

The semicolon means the sound plays whether the job succeeded or not. If you want different sounds for success and failure, use && and || instead:

./backup.sh && afplay /System/Library/Sounds/Glass.aiff || afplay /System/Library/Sounds/Basso.aiff

The caveat is that the sound goes to whatever output is active. If the Mac is muted, or the headphones you forgot about are connected, you hear nothing and the job still finished. Third-party pages mention extra options for volume and duration, but the man page I could verify lists only -h, so check afplay -h on your own system before relying on them. For longer jobs a sound is only half of a notification, and I still glance at the terminal before I trust it.

Further reading: afplay man page

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link