# How to play a sound when a Terminal command finishes on Mac

Use macOS afplay after a known command, choose whether failure should also alert you and keep notification errors separate from the command's result.

By [Rudra Satani](https://tapnoise.com/about/#maker), who makes TapNoise · 11 October 2026

In this post

For a quick success-only cue in Terminal, append `&& afplay` and a local sound file to the command you already intended to run. macOS includes `afplay`; no additional sound app is required.

## Try a harmless example

This waits one second and then plays the system Glass sound if that file is present:

`sleep 1 && afplay /System/Library/Sounds/Glass.aiff` 

Start with a modest output volume. Replace `sleep 1` with your known command only after confirming the sound and selected output.

## Choose the condition deliberately

`&&` runs the sound only when the first command exits successfully. A command followed by `; afplay ...` plays after either outcome, so the same sound can no longer tell you success from failure.

The final shell status can also become the player’s status. For scripts or CI, save and return the original command status rather than letting a missing sound file change the result. The [two-outcome example](https://tapnoise.com/blog/terminal-sound-success-failure/) demonstrates that pattern.

## Know where it runs

A command entered over SSH runs on the remote machine. Its sound player will not automatically use your local Mac’s speakers. Cloud jobs need an appropriate completion channel of their own.

For supported local coding agents, [TapNoise’s integration](https://tapnoise.com/docs/connect-coding-agents/) avoids appending a player to each turn. A finished command is still only an exit event, so read its output before treating the task as complete.

Sources: macOS `afplay -h` and shell conditional-command behaviour; [TapNoise agent guide](https://tapnoise.com/docs/connect-coding-agents/).

**About the author**

Rudra Satani makes TapNoise. Spotted a mistake? Email [support@tapnoise.com](mailto:support@tapnoise.com?subject=Blog%20correction), or reach out at [@rudraxx13](https://x.com/rudraxx13).

## Related guides

- [**What the agent sounds and reactions mean**Claude Code, Codex and Cursor each play a cue when they finish, need you or hit an error. Here is what each sound means and how to hear it.](https://tapnoise.com/docs/agent-sound-cues/)

## Hear TapNoise on your Mac

Every sound is made by TapNoise itself. Try the sounds on the homepage first, then download the app.

[Download TapNoise](https://tapnoise.com/download/) · [Try the sounds](https://tapnoise.com/#try)

## More from the blog

- [**How to remove agent sound hooks without losing other settings**Disconnect TapNoise from each agent before uninstalling, preserve unrelated configuration and understand why deleting an entire hooks file is unnecessary.](https://tapnoise.com/blog/remove-agent-sound-hooks-safely/)

- [**How to return to a waiting coding agent by clicking Tappy**Use TapNoise's desktop companion as a way back to a waiting local agent, and understand how clicking differs from sensor-based MacBook knocks.](https://tapnoise.com/blog/click-desktop-buddy-agent-window/)

- [**How to show a Mac notification after a Terminal task**Use the built-in osascript command for a simple completion notification, keep private command output out of the message and check notification permissions.](https://tapnoise.com/blog/terminal-notification-without-extra-app/)

- [**Local vs remote coding-agent alerts: where does the sound play?**A hook runs in the agent's environment. Understand why SSH, containers and cloud jobs do not automatically send a local Mac sound to your speakers.](https://tapnoise.com/blog/local-vs-remote-agent-sounds/)

Source: https://tapnoise.com/blog/play-sound-when-terminal-command-finishes/
