The simplest way would be to invoke a notification using Applescript after a given terminal command like so:
npm run build && osascript -e 'display notification "Complete" with title "npm run build"'
The next level would be to create a custom script in package.json
:
"scripts": {
"build-notify": "npm run build && osascript -e 'display notification \"Complete\" with title \"npm run build\"'"
}
Another option would be to create a custom alias to run the whole thing:
alias build="npm run build && osascript -e 'display notification \"Complete\" with title \"Build complete\"'"
Then run it like a regular terminal command: build
If you don't mind the audio, you could use the say
command instead:
npm run build && say done
.
There are also some tools that abstract this a bit, like https://github.com/julienXX/terminal-notifier and maybe many more.
At least on macOS Monterey one can issue from the terminal or a shell script:
To allow such notification one must go to "System preferences–Notifications & Focus–Script Editor" and select "Allow Notifications", and "Alerts" (display for three seconds) or "Banners" (display until closed). For silent ones, omit 'sound name "default"'.
– Kristjan Jonasson Sep 17 '22 at 11:37