notes_search
Search Apple Notes for specific text within titles, bodies, or specified folders. Customize results by limiting output and including/excluding note bodies for precise retrieval.
Instructions
[Apple Notes operations] Search for notes containing specific text
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| folder | No | Optional folder name to search in | |
| includeBody | No | Whether to include note body in results (default: true) | |
| limit | No | Maximum number of results to return (default: 5) | |
| query | Yes | Text to search for in notes (title and body) |
Implementation Reference
- src/categories/notes.ts:311-392 (handler)Handler function for the notes_search tool. This arrow function takes arguments (query, folder, limit, includeBody) and returns the AppleScript code that searches for matching notes in the Apple Notes application, constructs JSON output with note details.script: (args) => { const { query, folder = "", limit = 5, includeBody = true } = args; if (folder) { return ` tell application "Notes" set folderList to folders whose name is "${folder}" if length of folderList > 0 then set targetFolder to item 1 of folderList set matchingNotes to {} set allNotes to notes of targetFolder repeat with n in allNotes if name of n contains "${query}" or body of n contains "${query}" then set end of matchingNotes to n end if end repeat set resultCount to length of matchingNotes if resultCount > ${limit} then set resultCount to ${limit} set jsonResult to "[" repeat with i from 1 to resultCount set n to item i of matchingNotes set noteTitle to name of n set noteCreationDate to creation date of n set noteModDate to modification date of n ${includeBody ? 'set noteBody to body of n' : ''} set noteJson to "{\\"title\\": \\"" set noteJson to noteJson & noteTitle & "\\"" ${includeBody ? 'set noteJson to noteJson & ", \\"body\\": \\"" & noteBody & "\\""' : ''} set noteJson to noteJson & ", \\"creationDate\\": \\"" & noteCreationDate & "\\"" set noteJson to noteJson & ", \\"modificationDate\\": \\"" & noteModDate & "\\"}" set jsonResult to jsonResult & noteJson if i < resultCount then set jsonResult to jsonResult & ", " end repeat set jsonResult to jsonResult & "]" return jsonResult else return "Folder not found: ${folder}" end if end tell `; } else { return ` tell application "Notes" set matchingNotes to {} set allNotes to notes repeat with n in allNotes if name of n contains "${query}" or body of n contains "${query}" then set end of matchingNotes to n end if end repeat set resultCount to length of matchingNotes if resultCount > ${limit} then set resultCount to ${limit} set jsonResult to "[" repeat with i from 1 to resultCount set n to item i of matchingNotes set noteTitle to name of n set noteCreationDate to creation date of n set noteModDate to modification date of n ${includeBody ? 'set noteBody to body of n' : ''} set noteJson to "{\\"title\\": \\"" set noteJson to noteJson & noteTitle & "\\"" ${includeBody ? 'set noteJson to noteJson & ", \\"body\\": \\"" & noteBody & "\\""' : ''} set noteJson to noteJson & ", \\"creationDate\\": \\"" & noteCreationDate & "\\"" set noteJson to noteJson & ", \\"modificationDate\\": \\"" & noteModDate & "\\"}" set jsonResult to jsonResult & noteJson if i < resultCount then set jsonResult to jsonResult & ", " end repeat set jsonResult to jsonResult & "]" return jsonResult end tell `; }
- src/categories/notes.ts:394-415 (schema)Input schema for the notes_search tool, defining parameters: query (required string), folder (optional string), limit (optional number), includeBody (optional boolean).schema: { type: "object", properties: { query: { type: "string", description: "Text to search for in notes (title and body)" }, folder: { type: "string", description: "Optional folder name to search in" }, limit: { type: "number", description: "Maximum number of results to return (default: 5)" }, includeBody: { type: "boolean", description: "Whether to include note body in results (default: true)" } }, required: ["query"] }
- src/index.ts:35-35 (registration)Registration of the notesCategory, which includes the 'search' script that becomes the notes_search tool, via server.addCategory.server.addCategory(notesCategory);
- src/framework.ts:222-231 (registration)Dynamic tool registration in listTools handler: constructs tool name as category.name + '_' + script.name (e.g., 'notes_search'), includes description and schema.tools: this.categories.flatMap((category) => category.scripts.map((script) => ({ name: `${category.name}_${script.name}`, // Changed from dot to underscore description: `[${category.description}] ${script.description}`, inputSchema: script.schema || { type: "object", properties: {}, }, })), ),
- src/framework.ts:224-224 (registration)Specific line constructing the 'notes_search' tool name from 'notes' category and 'search' script.name: `${category.name}_${script.name}`, // Changed from dot to underscore