Created
October 5, 2025 22:54
-
-
Save adam-edison/f7ad54b60dbaa0e926837a68e9c3fb96 to your computer and use it in GitHub Desktop.
Play a sound on MacOS in zsh terminal after long-running command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Used for playing sound after a long command is executed | |
| source ~/.zsh/command-sound.zsh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is a hook in ZSH that runs before the command execution starts | |
| preexec() { | |
| cmd_start_time=$(date +%s) | |
| } | |
| # This is a hook in ZSH that runs before each command prompt is displayed | |
| precmd() { | |
| if [ -n "$cmd_start_time" ]; then | |
| cmd_end_time=$(date +%s) | |
| elapsed=$((cmd_end_time - cmd_start_time)) | |
| if [ $elapsed -gt 5 ]; then # 5 seconds threshold | |
| # Run in background to avoid blocking the terminal | |
| (afplay /System/Library/Sounds/Blow.aiff 2>/dev/null &) | |
| fi | |
| unset cmd_start_time | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment