Quick capture to Apple Notes: append text to a note with a hotkey
Important disclaimer
The script in this post was created by Claude Code.
I keep a running collection of AI prompts in an Apple Notes note called "Prompts". Opening Notes, finding the note and scrolling to the end every time got old, so I made a small app that I trigger from Keyboard Maestro. It opens a window, I type or paste a prompt, press ⌘Return, and the text is appended to the note. Notes never comes to the front.
What it does
- Opens a window titled "Add a new prompt" with a large multi-line text box and Cancel / OK buttons.
- Return adds a new line, ⌘Return clicks OK, Esc cancels.
- Appends the text to the end of the note under a bold date and time. Line breaks are kept, and
<,>and&appear as typed. - Creates the folder and the note if they don't exist yet.
- Starts Notes hidden if it isn't running and leaves it running in the background. If Notes is quit right after the edit, the change doesn't sync to iCloud (and your other devices) until you next open Notes on the Mac.
- Shows a notification with the text that was added.
Why an app and not an Execute AppleScript action
The input window is built with AppleScriptObjC. It needs to run in its own app, which is why it's saved as an application. When Keyboard Maestro runs an AppleScript action, the script runs in the background, and the window may not appear.
Setup
- Open Script Editor, create a new document and paste in the script below.
- Change the three properties at the top to match your setup.
accountNamemust match the account name in the Notes sidebar, for example"iCloud"or"On My Mac". - Choose File › Export…, set File Format to Application, and save it, for example as
~/Applications/Add to Prompts.app. - In Keyboard Maestro, create a new macro:
- Trigger: Hot Key Trigger with a shortcut of your choice
- Action: Open a File, Folder or Application, pointing at the app
- The first time it runs, macOS asks whether the app may control Notes. Click Allow. If you missed it, look under System Settings › Privacy & Security › Automation.
Customising
- Window size:
winWandwinHinaskForText() - Window title: the
labelWithString:line - Timestamp format: the
date '+%Y-%m-%d %H:%M'command inappendToNote()
Tested on macOS Sequoia 15.8.
The script
-- Add to Prompts: appends typed text to the Apple Notes note "Prompts"
use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property accountName : "iCloud"
property folderName : "Notes"
property noteName : "Prompts"
on run
set entry to my askForText()
if entry is missing value then return -- cancelled
set entry to my trimText(entry)
if entry is not "" then
my appendToNote(entry)
display notification entry with title "Added to " & noteName
end if
end run
-- Custom input window: bold title, multi-line text box, centered Cancel / OK
-- Return = new line, ⌘Return = OK, Esc = Cancel
on askForText()
set ca to current application
set winW to 520
set winH to 380
set margin to 20
set panel to ca's NSPanel's alloc()'s initWithContentRect:(ca's NSMakeRect(0, 0, winW, winH)) ¬
styleMask:(1 + 32768) ¬
backing:2 defer:false
panel's setTitlebarAppearsTransparent:true
panel's setTitleVisibility:1
panel's setMovableByWindowBackground:true
panel's setLevel:3
set content to panel's contentView()
-- title
set titleLabel to ca's NSTextField's labelWithString:"Add a new prompt"
titleLabel's setFont:(ca's NSFont's boldSystemFontOfSize:20)
titleLabel's setAlignment:2
titleLabel's setFrame:(ca's NSMakeRect(margin, winH - 58, winW - 2 * margin, 28))
content's addSubview:titleLabel
-- text box
set boxRect to ca's NSMakeRect(margin, 68, winW - 2 * margin, winH - 68 - 72)
set scroll to ca's NSScrollView's alloc()'s initWithFrame:boxRect
scroll's setHasVerticalScroller:true
scroll's setBorderType:2
set tv to ca's NSTextView's alloc()'s initWithFrame:(ca's NSMakeRect(0, 0, winW - 2 * margin, 200))
tv's setRichText:false
tv's setFont:(ca's NSFont's systemFontOfSize:13)
tv's setAutoresizingMask:2
tv's setAutomaticQuoteSubstitutionEnabled:false
tv's setAutomaticDashSubstitutionEnabled:false
tv's setTextContainerInset:(ca's NSMakeSize(4, 6))
scroll's setDocumentView:tv
content's addSubview:scroll
-- buttons, centered on one row
set btnW to 110
set gap to 16
set x0 to (winW - (2 * btnW + gap)) / 2
set cancelBtn to ca's NSButton's buttonWithTitle:"Cancel" target:me action:"cancelClicked:"
cancelBtn's setFrame:(ca's NSMakeRect(x0, margin, btnW, 32))
cancelBtn's setKeyEquivalent:(character id 27)
content's addSubview:cancelBtn
set okBtn to ca's NSButton's buttonWithTitle:"OK" target:me action:"okClicked:"
okBtn's setFrame:(ca's NSMakeRect(x0 + btnW + gap, margin, btnW, 32))
okBtn's setBezelColor:(ca's NSColor's systemGreenColor())
okBtn's setKeyEquivalent:return
okBtn's setKeyEquivalentModifierMask:1048576
content's addSubview:okBtn
-- show modally
ca's NSApp's activateIgnoringOtherApps:true
panel's |center|()
panel's makeKeyAndOrderFront:me
panel's makeFirstResponder:tv
set r to (ca's NSApp's runModalForWindow:panel) as integer
panel's orderOut:me
if r is 1 then return (tv's |string|()) as text
return missing value
end askForText
on okClicked:sender
current application's NSApp's stopModalWithCode:1
end okClicked:
on cancelClicked:sender
current application's NSApp's stopModalWithCode:0
end cancelClicked:
on appendToNote(entry)
set stamp to do shell script "date '+%Y-%m-%d %H:%M'"
set html to "<div><br></div><div><b>" & stamp & "</b></div><div>" & my htmlEscape(entry) & "</div>"
-- launch Notes hidden in the background if it isn't already running
if not (application "Notes" is running) then
do shell script "open -g -j -a Notes"
repeat 50 times
if application "Notes" is running then exit repeat
delay 0.1
end repeat
end if
tell application "Notes"
tell account accountName
if not (exists folder folderName) then make new folder with properties {name:folderName}
tell folder folderName
if exists note noteName then
set n to note noteName
set body of n to (body of n) & html
else
make new note with properties {body:"<h1>" & noteName & "</h1>" & html}
end if
end tell
end tell
end tell
-- leave Notes running (hidden) so it can push the change to iCloud;
-- quitting right away keeps the edit local until Notes is next opened
end appendToNote
on htmlEscape(t)
set t to my replaceText("&", "&", t)
set t to my replaceText("<", "<", t)
set t to my replaceText(">", ">", t)
set t to my replaceText(return & linefeed, linefeed, t)
set t to my replaceText(return, linefeed, t)
set t to my replaceText(linefeed, "<br>", t)
return t
end htmlEscape
on replaceText(findStr, replStr, t)
set AppleScript's text item delimiters to findStr
set parts to text items of t
set AppleScript's text item delimiters to replStr
set t to parts as text
set AppleScript's text item delimiters to ""
return t
end replaceText
on trimText(t)
set ws to {space, tab, return, linefeed}
repeat while t is not "" and (character 1 of t) is in ws
if length of t is 1 then return ""
set t to text 2 thru -1 of t
end repeat
repeat while t is not "" and (character -1 of t) is in ws
if length of t is 1 then return ""
set t to text 1 thru -2 of t
end repeat
return t
end trimText

