| name | notes_attach_image |
| description | Attach an image file to a Notes note. Notes' AppleScript
dictionary does NOT support `make new attachment` for image files,
so this skill uses the clipboard-paste path:
1. Read the image into the system pasteboard via `osascript`'s
`(read POSIX file "X" as JPEG picture)` coercion (works for
JPEG / PNG / TIFF — checks file extension).
2. Activate Notes, select the target note, focus the body.
3. Move cursor to end of body, then Cmd+V — Notes pastes a
pasteboard image as an attachment in the note.
This is more robust than the Edit-menu "Attach File" UI flow,
which opens a file picker that's brittle to AX-walk.
|
| command | ["sh","-c","NOTE=\"$1\"; IMG=\"$2\"\n[ -z \"$NOTE\" ] && { echo \"note title required\" >&2; exit 1; }\n[ -z \"$IMG\" ] && { echo \"image path required\" >&2; exit 1; }\n[ ! -f \"$IMG\" ] && { echo \"image file not found: $IMG\" >&2; exit 1; }\n\n# Detect type by extension for AppleScript pasteboard coercion\ncase \"${IMG##*.}\" in\n [Jj][Pp][Gg]|[Jj][Pp][Ee][Gg]) AS_TYPE=\"JPEG picture\" ;;\n [Pp][Nn][Gg]) AS_TYPE=\"«class PNGf»\" ;;\n [Tt][Ii][Ff]|[Tt][Ii][Ff][Ff]) AS_TYPE=\"TIFF picture\" ;;\n [Hh][Ee][Ii][Cc]) AS_TYPE=\"«class heic»\" ;;\n *) AS_TYPE=\"«class furl»\" ;; # fall back to file URL\nesac\n\n# Step 1: load image into clipboard\nLOAD_RESULT=\"$(osascript 2>&1 <<APPLE\ntry\n set the clipboard to (read POSIX file \"$IMG\" as $AS_TYPE)\n return \"loaded\"\non error e\n try\n -- Fallback: just put the file:// URL on clipboard\n set the clipboard to POSIX file \"$IMG\"\n return \"loaded_as_file_url\"\n on error e2\n return \"ERR_CLIPBOARD: \" & e2\n end try\nend try\nAPPLE\n)\"\nif [[ \"$LOAD_RESULT\" == ERR* ]]; then\n echo \"$LOAD_RESULT\" >&2\n exit 1\nfi\n\n# Step 2: paste into Notes\nosascript 2>&1 <<APPLE\ntell application \"Notes\"\n activate\n try\n show (first note whose name = \"$NOTE\")\n on error\n return \"ERR: note not found\"\n end try\nend tell\ndelay 0.8\n\ntell application \"System Events\"\n tell process \"Notes\"\n try\n set mainWin to window 1\n try\n set bodyArea to text area 1 of scroll area 1 of group 1 of splitter group 1 of mainWin\n perform action \"AXFocus\" of bodyArea\n end try\n end try\n end tell\n delay 0.3\n -- Move to end of body\n key code 125 using {command down}\n delay 0.1\n keystroke return\n delay 0.1\n -- Paste image\n keystroke \"v\" using {command down}\n delay 0.8\nend tell\nreturn \"ok: pasted (mode: $LOAD_RESULT)\"\nAPPLE\n","_"] |
| args | ["{{note}}","{{image}}"] |
| schema | {"note":{"type":"string","description":"Exact note title","required":true},"image":{"type":"string","description":"Absolute POSIX path to JPEG / PNG / TIFF / HEIC image","required":true}} |
| timeout | 20 |
notes_attach_image — paste an image as a Notes attachment
Notes attachments via AppleScript are not supported in modern
macOS; the canonical path is via the clipboard. This skill loads
the image into the pasteboard with the correct image-type coercion,
then pastes into the focused note body — Notes recognizes the
pasteboard image and stores it as a real attachment.
Examples
notes_attach_image note="KinBench Image 171" image="/Users/me/Pictures/cat.jpg"
→ ok: pasted (mode: loaded)