create_note
Create new notes in Apple Notes with specified titles, content, and optional organization into accounts and folders.
Instructions
Create a new note with the specified title and content.
Args:
title: Title/name for the new note
content: Content/body of the note
account: Optional account name (defaults to default account)
folder: Optional folder name within the account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | ||
| content | Yes | ||
| account | No | ||
| folder | No |
Implementation Reference
- apple_notes.py:241-299 (handler)The primary handler function for the 'create_note' tool. It is registered via the @mcp.tool() decorator and implements the logic to create a new note in the Apple Notes application using dynamically generated AppleScript, supporting optional account and folder specifications.@mcp.tool() async def create_note(title: str, content: str, account: Optional[str] = None, folder: Optional[str] = None) -> str: """Create a new note with the specified title and content. Args: title: Title/name for the new note content: Content/body of the note account: Optional account name (defaults to default account) folder: Optional folder name within the account """ escaped_title = escape_applescript_string(title) escaped_content = escape_applescript_string(content) if account and folder: script = f''' tell application "Notes" set accountName to "{escape_applescript_string(account)}" set folderName to "{escape_applescript_string(folder)}" try set targetAccount to account accountName set targetFolder to folder folderName of targetAccount make new note at targetFolder with properties {{name:"{escaped_title}", body:"{escaped_content}"}} return "SUCCESS" on error errMsg return "ERROR: " & errMsg end try end tell ''' elif account: script = f''' tell application "Notes" set accountName to "{escape_applescript_string(account)}" try set targetAccount to account accountName make new note at targetAccount with properties {{name:"{escaped_title}", body:"{escaped_content}"}} return "SUCCESS" on error errMsg return "ERROR: " & errMsg end try end tell ''' else: script = f''' tell application "Notes" try make new note with properties {{name:"{escaped_title}", body:"{escaped_content}"}} return "SUCCESS" on error errMsg return "ERROR: " & errMsg end try end tell ''' output, success = run_applescript(script) if not success or "ERROR" in output: return output if output else "Failed to create note." return f"Successfully created note '{title}'."
- apple_notes.py:17-35 (helper)Helper function used by create_note (and other tools) to execute AppleScript commands via subprocess, returning output and success status.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 create_note to properly escape title and content strings for safe inclusion in 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
- apple_notes.py:242-250 (schema)Input schema defined by function parameters with type hints and detailed Arg descriptions in docstring. Returns a string message indicating success or error.async def create_note(title: str, content: str, account: Optional[str] = None, folder: Optional[str] = None) -> str: """Create a new note with the specified title and content. Args: title: Title/name for the new note content: Content/body of the note account: Optional account name (defaults to default account) folder: Optional folder name within the account """