Skip to content

Instantly share code, notes, and snippets.

@Swiss-Mac-User
Created August 20, 2025 21:37
Show Gist options
  • Save Swiss-Mac-User/c4604994916a4060202d4093cc098ae6 to your computer and use it in GitHub Desktop.
Save Swiss-Mac-User/c4604994916a4060202d4093cc098ae6 to your computer and use it in GitHub Desktop.
Shell scripts to trigger custom macOS Notifications using osascript | https://swissmacuser.ch/native-macos-notifications-from-terminal-scripts/
osascript -e "display notification \"This notification comes straight from Terminal.app to your macOS Notification Center, thanks to AppleScript 🤓\""
osascript -e "display notification \"This notification comes straight from Terminal.app to your macOS Notification Center, thanks to AppleScript 🤓\" with title \"My Custom Notification\""
osascript -e "display notification \"This notification comes straight from Terminal.app to your macOS Notification Center, thanks to AppleScript 🤓\" with title \"My Custom Notification\" subtitle \"I love scripting\""
#!/usr/bin/env zsh
# Instructions:
# - Make this file executable first using `chmod +x notification-script.sh`
# - Run it from Terminal.app using: ./notification-script.sh "This is a notification"
# Learn more: https://swissmacuser.ch/native-macos-notifications-from-terminal-scripts/
# Function to send a Notification to get attention for the Script
function notify(){
local title="$2"
local text="$1"
/usr/bin/osascript -e "display notification \"$text\" with title \"$title\""
# Or with a subtitle, but note, this truncates Notification texts with too many characters!
#local subtitle="Terminal.app"
#/usr/bin/osascript -e "display notification \"$text\" with title \"$title\" subtitle \"$subtitle\""
}
# Check for user input and trigger Notification
if [ -n "$1" ]; then
notify "$1" "$0"
# exit OK
exit 0
else
echo -e "Usage: $0 \"This is a custom text\""
# exit with error:
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment