From e1b93ff4ef1c06e8b5ef051c40fda91d4689829e Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Mon, 20 Oct 2025 10:56:28 -0400 Subject: [PATCH] fix: escape special characters in AppleScript notifications Fixes AppleScript syntax error when notification messages or titles contain special characters like double quotes or backslashes. The osascript fallback path (when terminal-notifier is unavailable) was not properly escaping variables before passing them to AppleScript, causing syntax errors like "identifier can't go after this". Solution: Use sed to escape backslashes and double quotes in $MSG and $TITLE variables before interpolating them into the AppleScript command. Single quotes do not need escaping in AppleScript double-quoted strings. Tested with: - Double quotes - Single quotes/apostrophes - Parentheses - Backslashes - Mixed special characters Closes #3 --- templates/claude-code/scripts/smart-notify.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/templates/claude-code/scripts/smart-notify.sh b/templates/claude-code/scripts/smart-notify.sh index a8c9b16..c5d593e 100755 --- a/templates/claude-code/scripts/smart-notify.sh +++ b/templates/claude-code/scripts/smart-notify.sh @@ -51,5 +51,10 @@ if command -v terminal-notifier >/dev/null 2>&1; then -message "$MSG" \ -sound "$SOUND" else - osascript -e "display notification \"$MSG\" with title \"Claude Code ($SESSION_DIR) - $TITLE\" sound name \"$SOUND\"" + # Escape special characters for AppleScript (only double quotes and backslashes) + MSG_ESCAPED=$(printf '%s' "$MSG" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g') + TITLE_FULL="Claude Code ($SESSION_DIR) - $TITLE" + TITLE_ESCAPED=$(printf '%s' "$TITLE_FULL" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g') + + osascript -e "display notification \"$MSG_ESCAPED\" with title \"$TITLE_ESCAPED\" sound name \"$SOUND\"" fi