Skip to content

Conversation

@zackkatz
Copy link
Collaborator

Description

Fixes #3

Resolves AppleScript syntax error in smart-notify.sh when notification messages contain special characters.

Problem

The Stop hook was failing with syntax errors when messages contained special characters:

Stop hook error: Failed with non-blocking status code: 30:37: syntax error: A identifier can't go after this """. (-2740)

Solution

Added proper escaping for $MSG and $TITLE variables before passing to osascript:

  • Escape backslashes: \\\
  • Escape double quotes: "\"
  • Single quotes/apostrophes do not need escaping in AppleScript double-quoted strings

Changes

  • Updated templates/claude-code/scripts/smart-notify.sh line 54-60
  • Added escaping logic using sed for backslashes and double quotes
  • Added inline comment explaining the escaping strategy

Testing

Comprehensive testing with various special characters:

  • ✅ Double quotes: Message with "double quotes"
  • ✅ Single quotes: Message with 'single quotes'
  • ✅ Apostrophes: Complex: "test" (with) 'apostrophe'
  • ✅ Parentheses: Message with (parentheses)
  • ✅ Backslashes: Backslash \ test
  • ✅ Mixed special characters: Mixed: "quoted" and 'apostrophe' with \ backslash

All 8 test cases passed successfully with notifications displaying correctly on macOS.

Impact

  • ✅ Fixes Stop hook errors for macOS users without terminal-notifier installed
  • ✅ No breaking changes
  • ✅ Backward compatible with existing installations
  • ✅ Only affects osascript fallback path
  • ✅ Terminal-notifier path unchanged (already working correctly)

Screenshots

Notifications now display correctly with special characters instead of throwing AppleScript syntax errors.

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 verygoodplugins#3
@coderabbitai
Copy link

coderabbitai bot commented Oct 20, 2025

📝 Walkthrough

Walkthrough

The smart-notify.sh script is modified to properly escape special characters in message and title variables before passing them to AppleScript. This prevents syntax errors when notification content contains quotes, parentheses, or other special characters that would otherwise break the osascript command.

Changes

Cohort / File(s) Summary
AppleScript variable escaping
templates/claude-code/scripts/smart-notify.sh
Adds MSG_ESCAPED and TITLE_ESCAPED variables with sanitization of backslashes and double quotes; constructs TITLE_FULL and uses escaped values in osascript command to handle special characters in notification messages and titles

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "Fix AppleScript syntax error in smart-notify.sh" is clear, specific, and directly related to the main change in the codebase. It accurately summarizes the primary fix, which is resolving AppleScript syntax errors by properly escaping special characters in the smart-notify.sh script. The title is concise, free of noise, and a reviewer scanning commit history would immediately understand what this change addresses.
Linked Issues Check ✅ Passed The code changes directly address the requirements specified in issue #3. The issue requires properly escaping variables before passing them to AppleScript to resolve syntax errors caused by special characters. The PR implements exactly this: escaping backslashes (\→\\) and double quotes ("→\") in MSG and TITLE variables using sed before passing them to osascript. The raw summary confirms these escaping operations were applied, and the description details the implementation strategy, which matches the proposed solution in the linked issue.
Out of Scope Changes Check ✅ Passed All code changes are appropriately scoped to the issue requirements. The raw summary indicates modifications are confined to templates/claude-code/scripts/smart-notify.sh in the non-terminal notification path, with no alterations to exported/public entities or control flow outside of the AppleScript argument escaping. The PR description explicitly notes that only the osascript fallback path is affected and the terminal-notifier path remains unchanged, confirming no extraneous changes were introduced beyond what issue #3 requires.
Description Check ✅ Passed The pull request description is well-detailed and directly related to the changeset. It clearly explains the problem (AppleScript syntax errors when messages contain special characters), provides the solution (escaping backslashes and double quotes using sed), documents the specific lines modified, includes comprehensive testing results with multiple special character scenarios, and explains the impact on macOS users. The description is thorough and meaningful without being vague or off-topic.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c8a4d8 and e1b93ff.

📒 Files selected for processing (1)
  • templates/claude-code/scripts/smart-notify.sh (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
templates/claude-code/scripts/*.sh

📄 CodeRabbit inference engine (CLAUDE.md)

templates/claude-code/scripts/*.sh: Support scripts that create or transform queue entries must set only a top-level timestamp (ISO 8601 UTC) and avoid metadata.timestamp and date-derived tags
When adding tags in support scripts, use namespace-style tags and avoid free-form text
Use memory-filters.json to avoid storing trivial changes when generating queue entries

Files:

  • templates/claude-code/scripts/smart-notify.sh
🔇 Additional comments (1)
templates/claude-code/scripts/smart-notify.sh (1)

54-59: Solid escaping strategy for AppleScript special characters.

The implementation correctly handles the two critical escape sequences required for AppleScript double-quoted strings:

  • Backslashes are escaped first (\\\), avoiding double-escaping issues
  • Double quotes are escaped second ("\"
  • Using printf '%s' prevents shell interpretation of backslashes, which is essential

The escaping is applied to both the message and the full title (including SESSION_DIR), ensuring all user-controlled content is safe. Single quotes don't require escaping in AppleScript double-quoted strings, so they are correctly left as-is.

One forward-looking note: Line 59 interpolates $SOUND directly into the osascript command. Currently it's hardcoded to safe values ("Glass", "Blow", "Default"), but if this becomes dynamic in the future, it should also be escaped for consistency.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AppleScript syntax error in smart-notify.sh when messages contain special characters

1 participant