delete_note
Remove a specific note from Apple Notes by specifying its name and optional account location to manage your note collection.
Instructions
Delete a note by name.
Args:
note_name: Name of the note to delete
account: Optional account name where the note is located
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| note_name | Yes | ||
| account | No |
Implementation Reference
- apple_notes.py:350-394 (handler)The main handler function for the 'delete_note' tool. It constructs an AppleScript to delete the specified note from Apple Notes.app, handling optional account specification, error handling, and returns success/error messages.@mcp.tool() async def delete_note(note_name: str, account: Optional[str] = None) -> str: """Delete a note by name. Args: note_name: Name of the note to delete account: Optional account name where the note is located """ escaped_name = escape_applescript_string(note_name) 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 delete targetNote 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 delete targetNote 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 delete note '{note_name}'." return f"Successfully deleted note '{note_name}'."
- apple_notes.py:350-350 (registration)The @mcp.tool() decorator registers the delete_note function as an MCP tool.@mcp.tool()
- apple_notes.py:351-357 (schema)Type hints and docstring defining the input schema (note_name: str, optional account: str) and output (str).async def delete_note(note_name: str, account: Optional[str] = None) -> str: """Delete a note by name. Args: note_name: Name of the note to delete account: Optional account name where the note is located """
- apple_notes.py:37-44 (helper)Helper function used to escape the note_name 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:17-35 (helper)Helper function used by delete_note to execute the AppleScript command.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