You start a long job, switch to the browser, and forget to check back. A notification can come to you.
AppleScript has a display notification command, and osascript runs it from the shell:
osascript -e 'display notification "Backup finished" with title "Terminal" sound name "Glass"'
The sound names are the ones in /System/Library/Sounds, without the extension. Chain it after any command:
./backup.sh; osascript -e 'display notification "Exit code '"$?"'" with title "backup.sh"'
The odd quoting puts the shell’s $? inside the AppleScript string, so the notification says whether it worked. For anything more than that I’d wrap it in a small function:
notify() { osascript -e "display notification \"$1\" with title \"Terminal\""; }
make build; notify "build done"
The notification belongs to the app that ran osascript, usually Script Editor or your terminal, so check that app’s notification settings if nothing shows up. Focus modes also hide it. Quotes in your message will break the AppleScript string, so keep the text simple or escape them. Over SSH this shows the notification on the Mac you are logged in to, not the one in front of you.
Further reading: Displaying notifications (Mac Automation Scripting Guide), osascript man page (macOS)