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: osascript display notification tells you when a terminal job is done

Terminal
~/tips/tip-terminal-osascript-notification

osascript -e 'display notification "Backup finished" with title "Terminal" sound name "Glass"'

Shows a macOS notification from a script or after a long command.

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)

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