Create, read, search, and delete Apple Notes using JXA (JavaScript for Automation) via osascript. All examples work from the command line on macOS.
apple-notes-install-auth (permissions granted)# JXA: Create a note in the default folder
osascript -l JavaScript -e '
const Notes = Application("Notes");
const defaultFolder = Notes.defaultAccount.folders[0];
const newNote = Notes.Note({
name: "Hello from Automation",
body: "<h1>Hello World</h1><p>This note was created via JXA at " + new Date().toISOString() + "</p>"
});
defaultFolder.notes.push(newNote);
newNote.id();
'
# AppleScript equivalent:
osascript -e '
tell application "Notes"
tell account "iCloud"
make new note at folder "Notes" with properties {name:"Hello AppleScript", body:"<p>Created via AppleScript</p>"}
end tell
end tell
'
# List notes with title and creation date
osascript -l JavaScript -e '
const Notes = Application("Notes");
const notes = Notes.defaultAccount.notes();
notes.slice(0, 10).map(n =>
`${n.name()} | Created: ${n.creationDate().toISOString().split("T")[0]}`
).join("\n");
'
# Read note body (returns HTML)
osascript -l JavaScript -e '
const Notes = Application("Notes");
const notes = Notes.defaultAccount.notes();
const target = notes.find(n => n.name() === "Hello from Automation");
if (target) {
`Title: ${target.name()}\nBody: ${target.body()}\nModified: ${target.modificationDate()}`;
} else {
"Note not found";
}
'
# Search by keyword in note name
osascript -l JavaScript -e '
const Notes = Application("Notes");
const query = "Hello";
const results = Notes.defaultAccount.notes().filter(n =>
n.name().toLowerCase().includes(query.toLowerCase())
);
results.map(n => n.name()).join("\n") || "No results";
'
# Create a folder and add a note to it
osascript -l JavaScript -e '
const Notes = Application("Notes");
const account = Notes.defaultAccount;
// Create folder if it does not exist
let folder = account.folders().find(f => f.name() === "Automation");
if (!folder) {
folder = Notes.Folder({ name: "Automation" });
account.folders.push(folder);
}
// Add note to folder
const note = Notes.Note({
name: "Organized Note",
body: "<p>This note lives in the Automation folder.</p>"
});
folder.notes.push(note);
`Created in folder: ${folder.name()}`;
'
# Delete by name (moves to Recently Deleted)
osascript -l JavaScript -e '
const Notes = Application("Notes");
const notes = Notes.defaultAccount.notes();
const target = notes.find(n => n.name() === "Hello from Automation");
if (target) {
Notes.delete(target);
"Note deleted";
} else {
"Note not found";
}
'
| Property | Type | Writable | Description |
|---|---|---|---|
name |
string | Yes | Note title (first line) |
body |
string (HTML) | Yes | Full note content as HTML |
id |
string | No | Unique identifier |
creationDate |
Date | No | When note was created |
modificationDate |
Date | No | Last modification |
container |
Folder | No | Parent folder |
| Error | Cause | Solution |
|---|---|---|
Notes got an error |
Notes.app not running | Add Notes.activate() first |
| Empty body | Note has no text content | Check note is not just an image |
Can't make folder |
Folder already exists | Check before creating |
| Slow response | iCloud sync in progress | Wait for sync; use local account |
Proceed to apple-notes-local-dev-loop for development workflow setup.