Skip to content

Fix AppleScript execution for multi-line scripts#3

Open
jbkjr wants to merge 1 commit intoSiddhant-K-code:mainfrom
jbkjr:fix/applescript-multiline-execution
Open

Fix AppleScript execution for multi-line scripts#3
jbkjr wants to merge 1 commit intoSiddhant-K-code:mainfrom
jbkjr:fix/applescript-multiline-execution

Conversation

@jbkjr
Copy link

@jbkjr jbkjr commented Jan 25, 2026

Summary

  • Fixes AppleScript execution that was broken for all multi-line scripts
  • The issue caused "syntax error: Expected end of line but found 'tell'" errors when creating notes

Problem

The previous implementation in runAppleScript() replaced all newlines with spaces:

const sanitizedScript = script.trim().replace(/[\r\n]+/g, ' ');

This resulted in invalid AppleScript like:

osascript -e 'tell application "Notes"         tell account "iCloud" ...'

AppleScript requires newlines or semicolons between statements - spaces don't work.

Solution

  • Split the script into individual lines
  • Pass each line as a separate -e argument to osascript (the documented way to run multi-line scripts)
  • Properly escape single quotes in the script content
const lines = script.trim().split(/\r?\n/).map(line => line.trim()).filter(line => line.length > 0);
const args = lines.map(line => `-e '${escapeForShellSingleQuotes(line)}'`).join(' ');

Test plan

  • Tested create-note - now works correctly
  • Tested search-notes - works correctly
  • Tested get-note-content - works correctly

🤖 Generated with Claude Code

The previous implementation replaced newlines with spaces when executing
AppleScript, which caused syntax errors because AppleScript requires
newlines or semicolons between statements.

This fix:
- Splits the script into individual lines
- Passes each line as a separate -e argument to osascript
- Properly escapes single quotes in the script content

Fixes the "syntax error: Expected end of line but found 'tell'" error
that occurred when creating notes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant