update_note
Modify existing Apple Notes content by specifying the note name and providing new text, optionally selecting the account where the note is stored.
Instructions
Update the content of an existing note.
Args:
note_name: Name of the note to update
new_content: New content for the note
account: Optional account name where the note is located
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| note_name | Yes | ||
| new_content | Yes | ||
| account | No |
Implementation Reference
- apple_notes.py:301-347 (handler)The @mcp.tool() decorator registers and defines the handler for the 'update_note' tool. It escapes the note name and content, constructs an AppleScript to find and update the note's body (searching all accounts if no account specified), executes it via subprocess, and returns success/error messages.@mcp.tool() async def update_note(note_name: str, new_content: str, account: Optional[str] = None) -> str: """Update the content of an existing note. Args: note_name: Name of the note to update new_content: New content for the note account: Optional account name where the note is located """ escaped_name = escape_applescript_string(note_name) escaped_content = escape_applescript_string(new_content) if account: script = f''' tell application "Notes" set accountName to "{escape_applescript_string(account)}" set noteName to "{escaped_name}" try set targetAccount to account accountName set targetNote to note noteName of targetAccount set body of targetNote to "{escaped_content}" return "SUCCESS" on error errMsg return "ERROR: " & errMsg end try end tell ''' else: script = f''' tell application "Notes" set noteName to "{escaped_name}" repeat with anAccount in accounts try set targetNote to note noteName of anAccount set body of targetNote to "{escaped_content}" return "SUCCESS" end try end repeat return "ERROR: Note not found" end tell ''' output, success = run_applescript(script) if not success or "ERROR" in output: return output if output else f"Failed to update note '{note_name}'." return f"Successfully updated note '{note_name}'."
- apple_notes.py:17-34 (helper)Helper function used by update_note to execute AppleScript commands via subprocess and handle errors/timeouts.def run_applescript(script: str) -> tuple[str, bool]: """Run an AppleScript command and return the output.""" try: result = subprocess.run( ["osascript", "-e", script], capture_output=True, text=True, timeout=30 ) if result.returncode == 0: return result.stdout.strip(), True else: error_msg = result.stderr.strip() or result.stdout.strip() return f"Error: {error_msg}", False except subprocess.TimeoutExpired: return "Error: AppleScript execution timed out", False except Exception as e: return f"Error: {str(e)}", False
- apple_notes.py:37-43 (helper)Helper function used by update_note to properly escape strings for safe insertion into AppleScript.def escape_applescript_string(text: str) -> str: """Escape special characters for AppleScript strings.""" # Replace backslashes, quotes, and newlines text = text.replace("\\", "\\\\") text = text.replace('"', '\\"') text = text.replace("\n", "\\n") return text