Merge pull request #16 from dmitmel/master

Improve notifications on macOS
This commit is contained in:
Michael Aquilina 2019-08-01 13:38:53 +01:00 committed by GitHub
commit 83b7646472
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View file

@ -42,10 +42,11 @@ function _auto_notify_message() {
fi
notify-send "$title" "$body" "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME"
elif [[ "$platform" == "Darwin" ]]; then
# We need to escape quotes since we are passing a script into a command
body="${body//\"/\\\"}"
title="${title//\"/\\\"}"
osascript -e "display notification \"$body\" with title \"$title\""
osascript \
-e 'on run argv' \
-e 'display notification (item 1 of argv) with title (item 2 of argv)' \
-e 'end run' \
"$body" "$title"
else
printf "Unknown platform for sending notifications: $platform\n"
printf "Please post an issue on gitub.com/MichaelAquilina/zsh-auto-notify/issues/\n"

View file

@ -92,7 +92,7 @@
assert "$lines[4]" same_as "--urgency=normal --expire-time=15000"
}
@test 'auto-notify-send sends notification on MacOSX' {
@test 'auto-notify-send sends notification on macOS' {
AUTO_COMMAND="f bar -r"
AUTO_COMMAND_FULL="foo bar -r"
AUTO_COMMAND_START=11080
@ -108,8 +108,8 @@
run _auto_notify_send
assert $state equals 0
assert "$lines[1]" same_as '-e display notification "Total time: 20 seconds'
assert "$lines[2]" same_as 'Exit code: 0" with title "\"f bar -r\" Completed"'
assert "$lines[1]" same_as '-e on run argv -e display notification (item 1 of argv) with title (item 2 of argv) -e end run Total time: 20 seconds'
assert "$lines[2]" same_as 'Exit code: 0 "f bar -r" Completed'
}
@test 'auto-notify-send sends warning on unsupported platform' {