Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const notesManager = new AppleNotesManager();
const createNoteSchema = {
title: z.string().min(1, "Title is required"),
content: z.string().min(1, "Content is required"),
tags: z.array(z.string()).optional()
tags: z.array(z.string()).optional(),
folder: z.string().optional().describe("Folder name to save the note to (optional)")
};

const searchSchema = {
Expand All @@ -33,9 +34,9 @@ const getNoteSchema = {
server.tool(
"create-note",
createNoteSchema,
async ({ title, content, tags = [] }: CreateNoteParams) => {
async ({ title, content, tags = [], folder }: CreateNoteParams) => {
try {
const note = notesManager.createNote(title, content, tags);
const note = notesManager.createNote(title, content, tags, folder);
if (!note) {
return {
content: [{
Expand Down
33 changes: 26 additions & 7 deletions src/services/appleNotesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,36 @@ export class AppleNotesManager {
* @param title - The note title
* @param content - The note content
* @param tags - Optional array of tags
* @param folder - Optional folder name (Apple Notes folders are flat, use exact folder name e.g., "Work")
* @returns The created note object or null if creation fails
*/
createNote(title: string, content: string, tags: string[] = []): Note | null {
createNote(title: string, content: string, tags: string[] = [], folder?: string): Note | null {
const formattedContent = formatContent(content);
const script = `
tell application "Notes"
tell account "${this.ICLOUD_ACCOUNT}"
make new note with properties {name:"${title}", body:"${formattedContent}"}
const escapedTitle = title.replace(/"/g, '\\"');

// Build AppleScript with optional folder targeting
// Note: Apple Notes folders are flat at the account level in AppleScript
let script: string;
if (folder) {
const escapedFolder = folder.replace(/"/g, '\\"');
script = `
tell application "Notes"
tell account "${this.ICLOUD_ACCOUNT}"
tell folder "${escapedFolder}"
make new note with properties {name:"${escapedTitle}", body:"${formattedContent}"}
end tell
end tell
end tell
end tell
`;
`;
} else {
script = `
tell application "Notes"
tell account "${this.ICLOUD_ACCOUNT}"
make new note with properties {name:"${escapedTitle}", body:"${formattedContent}"}
end tell
end tell
`;
}

const result = runAppleScript(script);
if (!result.success) {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface CreateNoteParams {
title: string;
content: string;
tags?: string[];
folder?: string;
}

export interface SearchParams {
Expand Down