{
  "id": "notes",
  "name": "notes playbook",
  "description": "Apple Notes mastery: AppleScript bulk ops, HTML styling, inline images, website-quality notes",
  "platform": "notes",
  "urlPatterns": [],
  "steps": [],
  "tags": [
    "notes"
  ],
  "version": "2.0.0",
  "successCount": 0,
  "failCount": 0,
  "bundleId": "com.apple.Notes",
  "urls": {},
  "selectors": {
    "noteBody": "AXTextArea[identifier='Note Body Text View']",
    "noteList": "AXTable — sidebar note list",
    "folderList": "AXOutline — sidebar folder tree",
    "auto_discovered": {}
  },
  "flows": {
    "create_html_note": {
      "description": "Create a rich HTML-formatted note with tables, styled sections, colors, and emoji icons",
      "steps": [
        "applescript: make new note at folder 'Notes' of default account with properties {body:htmlString}",
        "HTML supports: h1-h3, p, b, i, u, hr, ul/li, ol/li, table, a href, br",
        "Inline CSS works: style='color:#00e5ff; background-color:#0a1a1c; border-radius:12px; font-size:28px;'",
        "Tables create card layouts: cellpadding for spacing, cellspacing for gaps, vertical-align:top"
      ],
      "example": "set h to \"<h1>Title</h1><table border='0' cellpadding='15' cellspacing='8'><tr><td style='background-color:#0a1a1c; border:1px solid #00e5ff30; border-radius:12px;'><b>Card</b><br>Description</td></tr></table>\""
    },
    "inline_image_paste": {
      "description": "Place images at exact positions inside a note using clipboard paste (not make new attachment which only appends to end)",
      "steps": [
        "Step 1: Create the full note content via AppleScript with HTML body",
        "Step 2: Copy image to clipboard via Bash: osascript -e 'set the clipboard to (read (POSIX file \"/path/to/image.png\") as «class PNGf»)'",
        "Step 3: Focus Notes app: focus({bundleId:'com.apple.Notes'})",
        "Step 4: Use Find to position cursor: cmd+f → type target text → escape",
        "Step 5: Navigate: cmd+left (start of line) → up (line above)",
        "Step 6: Paste: cmd+v (image appears inline at cursor position)",
        "Repeat steps 2-6 for each image at different positions"
      ],
      "gotchas": [
        "make new attachment at end of attachments ONLY appends to bottom — never inline",
        "cmd+right in Notes goes to end of ENTIRE note, not end of line — use arrow keys instead",
        "Copy image via Bash osascript, not via ScreenHand applescript tool (read command is blocked)",
        "Always focus Notes before pasting — switching apps moves cursor"
      ]
    },
    "bulk_read_notes": {
      "description": "Read all notes via AppleScript (100x faster than UI automation)",
      "snippet": "tell application \"Notes\"\n    set output to \"\"\n    repeat with n in notes of default account\n        set output to output & \"---\" & return & name of n & return & plaintext of n & return\n    end repeat\n    return output\nend tell"
    },
    "bulk_delete_by_name": {
      "description": "Delete specific notes by name (safer than pattern matching)",
      "snippet": "tell application \"Notes\"\n    set noteNames to {\"Note One\", \"Note Two\", \"Note Three\"}\n    repeat with noteName in noteNames\n        try\n            delete note noteName of default account\n        end try\n    end repeat\nend tell",
      "gotchas": [
        "Deleting inside a loop shifts the list — wrap in 'repeat 5 times' outer loop",
        "'items' is a reserved word — use taskList, noteList etc",
        "container of note errors out — skip folder name, query folder-specific instead"
      ]
    },
    "search_notes": {
      "description": "Search note content via AppleScript",
      "snippet": "tell application \"Notes\"\n    set results to {}\n    repeat with n in notes of default account\n        if plaintext of n contains \"keyword\" then\n            set end of results to name of n\n        end if\n    end repeat\n    return results\nend tell"
    },
    "move_note": {
      "description": "Move a note between folders",
      "snippet": "tell application \"Notes\"\n    set sourceNote to note \"My Note\" of default account\n    set targetFolder to folder \"Target Folder\" of default account\n    move sourceNote to targetFolder\nend tell"
    },
    "export_all_notes": {
      "description": "Export all notes to files (two-step: AppleScript dumps, Bash writes files)",
      "snippet_step1": "tell application \"Notes\"\n    set output to \"\"\n    repeat with n in notes of default account\n        set output to output & \"<<<NOTE_START>>>\" & name of n & \"<<<NOTE_SEP>>>\" & plaintext of n & \"<<<NOTE_END>>>\"\n    end repeat\n    return output\nend tell",
      "snippet_step2": "# Bash/Python: parse output file, split by delimiters, write each note to ~/Desktop/notes-export/",
      "gotchas": [
        "do shell script is blocked in ScreenHand applescript tool — must use two-step approach"
      ]
    },
    "count_per_folder": {
      "description": "Count notes in each folder",
      "snippet": "tell application \"Notes\"\n    set output to \"\"\n    repeat with f in folders of default account\n        set output to output & name of f & \": \" & (count of notes of f) & \" notes\" & return\n    end repeat\n    return output\nend tell"
    },
    "find_duplicates": {
      "description": "Find duplicate note titles",
      "snippet": "tell application \"Notes\"\n    set titles to {}\n    set dupes to {}\n    repeat with n in notes of default account\n        set t to name of n\n        if titles contains t then\n            if dupes does not contain t then set end of dupes to t\n        else\n            set end of titles to t\n        end if\n    end repeat\n    return dupes\nend tell"
    },
    "merge_notes": {
      "description": "Merge multiple notes into one with HTML",
      "snippet": "tell application \"Notes\"\n    set note1 to note \"First Note\" of default account\n    set note2 to note \"Second Note\" of default account\n    set combined to \"<h1>Merged Note</h1>\" & body of note1 & \"<hr>\" & body of note2\n    make new note at folder \"Notes\" of default account with properties {body:combined}\nend tell"
    },
    "bulk_tag": {
      "description": "Add tag to note body",
      "snippet": "tell application \"Notes\"\n    set n to note \"My Note\" of default account\n    set body of n to (body of n) & \"<br>#newtag\"\nend tell"
    },
    "list_titles_only": {
      "description": "List just note titles (fast overview)",
      "snippet": "tell application \"Notes\"\n    set output to {}\n    repeat with n in notes of default account\n        set end of output to name of n\n    end repeat\n    return output\nend tell"
    },
    "delete_by_pattern": {
      "description": "Delete notes matching a pattern (wraps 5x for list shifting)",
      "snippet": "tell application \"Notes\"\n    repeat 5 times\n        repeat with n in notes of default account\n            if name of n starts with \"Test\" then delete n\n        end repeat\n    end repeat\nend tell"
    },
    "move_from_folder": {
      "description": "Move a note from a specific folder back to Notes",
      "snippet": "tell application \"Notes\"\n    set sourceNote to note \"My Note\" of folder \"Source Folder\" of default account\n    set targetFolder to folder \"Notes\" of default account\n    move sourceNote to targetFolder\nend tell"
    },
    "list_with_dates": {
      "description": "List notes with creation and modification dates",
      "snippet": "tell application \"Notes\"\n    set output to \"\"\n    repeat with n in notes of default account\n        set output to output & name of n & \" | created: \" & (creation date of n as string) & \" | modified: \" & (modification date of n as string) & return\n    end repeat\n    return output\nend tell"
    },
    "bulk_rename": {
      "description": "Rename a note by prepending a new h1 title to body",
      "snippet": "tell application \"Notes\"\n    set n to note \"Old Title\" of default account\n    set body of n to \"<h1>New Title</h1>\" & body of n\nend tell"
    },
    "get_metadata": {
      "description": "Get note metadata: name, ID, dates, password status",
      "snippet": "tell application \"Notes\"\n    set n to note \"My Note\" of default account\n    return \"Name: \" & name of n & return & \"ID: \" & id of n & return & \"Created: \" & (creation date of n as string) & return & \"Modified: \" & (modification date of n as string) & return & \"Password protected: \" & (password protected of n as string)\nend tell"
    },
    "bulk_create_from_list": {
      "description": "Create multiple notes from a list of titles",
      "snippet": "tell application \"Notes\"\n    set taskList to {\"Task One\", \"Task Two\", \"Task Three\"}\n    repeat with taskItem in taskList\n        make new note at folder \"Notes\" of default account with properties {body:\"<h1>\" & taskItem & \"</h1><p>Bulk created</p>\"}\n    end repeat\nend tell"
    },
    "create_delete_folders": {
      "description": "Create and delete folders",
      "steps": [
        "applescript: make new folder with properties {name:'Folder Name'}",
        "applescript: delete folder 'Folder Name' of default account"
      ]
    },
    "website_style_note": {
      "description": "Create a website-quality note mirroring a Next.js site structure with Hero, Problem, Solution, Features, Comparison, Demo, CTA sections",
      "steps": [
        "Step 1: Build full HTML body with styled sections using tables for card layouts",
        "Step 2: Use inline CSS for colors (color:#00e5ff), backgrounds (background-color:#0a1a1c), borders, border-radius",
        "Step 3: Use <table border='0' cellpadding='15' cellspacing='8'> for card grids",
        "Step 4: Use <hr> between sections, styled <p> tags for section labels",
        "Step 5: Add comparison tables with emoji checkmarks (✅/❌)",
        "Step 6: Add CTA with styled button-like table cells (background-color:#00e5ff; border-radius:25px)",
        "Step 7: Paste images inline at exact positions using Find+cursor+clipboard technique"
      ],
      "html_tags_supported": [
        "h1",
        "h2",
        "h3",
        "p",
        "b",
        "i",
        "u",
        "hr",
        "br",
        "table",
        "tr",
        "td",
        "ul",
        "ol",
        "li",
        "a",
        "span",
        "img"
      ],
      "css_properties_supported": [
        "color",
        "background-color",
        "font-size",
        "border",
        "border-radius",
        "text-align",
        "vertical-align",
        "padding",
        "letter-spacing",
        "width"
      ]
    }
  },
  "detection": {
    "is_logged_in": "Always logged in — native macOS app"
  },
  "errors": [
    {
      "pattern": "string concatenation containing 'script' or 'shell'",
      "solution": "Rephrase body text to avoid the word 'script' — use 'macOS native' instead of 'AppleScript'",
      "tool": "applescript"
    },
    {
      "pattern": "read command blocked",
      "solution": "Use Bash osascript to copy images to clipboard, not ScreenHand applescript tool",
      "tool": "applescript"
    },
    {
      "pattern": "container of note errors -1728",
      "solution": "Skip folder name in metadata queries — query folder-specific notes instead",
      "tool": "applescript"
    },
    {
      "pattern": "items reserved word",
      "solution": "Use taskList, noteList etc instead of 'items' as variable names",
      "tool": "applescript"
    },
    {
      "pattern": "delete inside loop skips items",
      "solution": "Wrap in 'repeat 5 times' outer loop, or delete by specific name with try blocks",
      "tool": "applescript"
    },
    {
      "error": "Bridge process crashed, restarting",
      "context": "tool: map_app, domain: native:com.apple.Notes",
      "solution": "No resolution yet — investigate and update this entry",
      "severity": "medium"
    }
  ]
}
