Created
August 20, 2025 21:37
-
-
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/
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
osascript -e "display notification \"This notification comes straight from Terminal.app to your macOS Notification Center, thanks to AppleScript 🤓\"" |
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
osascript -e "display notification \"This notification comes straight from Terminal.app to your macOS Notification Center, thanks to AppleScript 🤓\" with title \"My Custom Notification\"" |
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
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\"" |
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
#!/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