Skip to content

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

@zackkatz

Description

@zackkatz

Problem

The smart-notify.sh script fails with AppleScript syntax error when variables contain special characters (quotes, parentheses, etc.):

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

Root Cause

Line 54 uses improper quote escaping when passing variables to osascript:

osascript -e "display notification \"$MSG\" with title \"Claude Code ($SESSION_DIR) - $TITLE\" sound name \"$SOUND\""

When $MSG, $SESSION_DIR, or $TITLE contain quotes, parentheses, or other special characters, they break the AppleScript syntax.

Reproduction

  1. Install Claude Code hooks with npx @verygoodplugins/mcp-automem claude-code
  2. Trigger a Stop hook where the assistant message contains quotes or special characters
  3. Observe the syntax error in hook output

Proposed Solution

Properly escape variables before passing to AppleScript:

  • Use printf with sed to escape quotes and special characters
  • Or use AppleScript's quoted form for proper escaping
  • Or pass variables through heredoc

Impact

  • Affects macOS users without terminal-notifier installed (fallback path)
  • Stop hooks fail but don't block Claude Code operation (non-blocking error)
  • Error appears in hook output logs

Environment

  • macOS (affects osascript fallback path)
  • Claude Code hooks installed via mcp-automem
  • Users without terminal-notifier installed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions