Skip to content

A Node.js tool to export Apple Notes to Markdown files with metadata preservation and folder structure mirroring

Notifications You must be signed in to change notification settings

adamgoth/apple-notes-export

Repository files navigation

Apple Notes Export Tool

A Node.js tool to export Apple Notes to Markdown files with metadata preservation and folder structure mirroring.

Features

  • Preserves Folder Structure: Mirrors your Apple Notes folder hierarchy in the exported files
  • HTML to Markdown Conversion: Uses Turndown to convert Apple Notes' HTML content to clean Markdown
  • Metadata Preservation: Adds front matter with:
    • Note title
    • Folder path
    • Creation date
    • Modification date
    • Apple Note ID
  • Filename Sanitization: Removes special characters and ensures cross-platform compatibility
  • Progress Indicators: Shows export progress with percentage completion and folder paths
  • Duplicate Handling: Automatically appends numbers to duplicate filenames
  • Error Handling: Gracefully handles notes that can't be accessed
  • Search Filtering: Export only notes matching specific queries

Installation

  1. Install the required dependency:

    npm install turndown

    Or install globally:

    npm install -g turndown
  2. Make the scripts executable (if not already):

    chmod +x notes-export.js
    chmod +x notes-export-with-folders.js

Usage

Export with Folder Structure (Recommended)

Export all notes while preserving the Apple Notes folder hierarchy:

./notes-export-with-folders.js

Specify a custom output directory:

./notes-export-with-folders.js -o ~/Documents/my-notes

Export to Flat Directory

If you prefer all notes in a single directory without folders:

./notes-export.js

Filter Notes by Query

Export only notes matching a search query:

./notes-export-with-folders.js -q "meeting" -o ./meeting-notes

Export from Specific Folder

Export notes from a specific folder only:

# Export from a top-level folder
./notes-export-with-folders.js -f "Work" -o ./work-notes

# Export from a nested folder
./notes-export-with-folders.js -f "Personal/Journal" -o ./journal-export

# Combine folder and query filters
./notes-export-with-folders.js -f "Projects" -q "2024" -o ./2024-projects

Export Single Note by Name

Export a specific note by searching for its name:

# Search for notes containing "Meeting Notes"
./export-single-note.js "Meeting Notes"

# Export with exact name match
./export-single-note.js "Budget 2024" --exact

# Specify output directory
./export-single-note.js "Project Plan" -o ~/Desktop/

# Using npm script
npm run export-note "Meeting Notes" -- -o ./my-note

Command Line Options

For bulk export scripts:

  • -o, --output <dir> - Output directory (default: ./notes-export)
  • -q, --query <text> - Filter notes by search query
  • -f, --folder <name> - Export only from specific folder
  • -h, --help - Show help message

For single note export:

  • -o, --output <dir> - Output directory (default: ./single-note-export)
  • -e, --exact - Match exact note name (case-insensitive)
  • -h, --help - Show help message

Example Output Structure

When using notes-export-with-folders.js, your exported notes will mirror the Apple Notes structure:

notes-export/
├── Personal/
│   ├── Journal/
│   │   ├── 2024_Reflections.md
│   │   └── Daily_Gratitude.md
│   └── Ideas/
│       └── App_Concepts.md
├── Work/
│   ├── Projects/
│   │   ├── Q1_Planning.md
│   │   └── Budget_2024.md
│   └── Meeting_Notes.md
└── Quick_Notes.md  # Notes in root (no folder)

Each exported note includes front matter:

---
title: "Q1 Planning"
folder: "Work/Projects"
created: Tuesday, January 15, 2025 at 10:30:00 AM
modified: Wednesday, January 16, 2025 at 2:45:00 PM
apple_note_id: x-coredata://12345678-ABCD-1234-5678-123456789ABC/Note/p123
---

# Q1 Planning

## Objectives

- Launch new feature set
- Increase user engagement by 20%
- Hire 3 new engineers

...

Scripts Overview

  • notes-export-with-folders.js - Exports notes while preserving Apple Notes folder structure (recommended)
  • notes-export.js - Exports all notes to a single flat directory
  • export-single-note.js - Export a single note by searching for its name
  • notes-cli.js - Base class for interacting with Apple Notes via AppleScript

Troubleshooting

"turndown package is not installed" Error

Run npm install turndown in the script directory.

Permission Errors

  • Ensure you have write permissions for the output directory
  • On macOS, you may need to grant Terminal/iTerm access to Apple Notes in System Preferences > Security & Privacy > Automation

Notes Not Exporting

  • Check that Apple Notes is installed and has notes
  • Try running without a query filter first
  • Some system notes or locked notes may not be accessible

Folder Names with Special Characters

The exporter automatically sanitizes folder and file names to ensure compatibility across different operating systems. Special characters are replaced with safe alternatives.

Integration with notes-cli.js

These export scripts extend the NotesManager class from notes-cli.js and can be used alongside it:

  • notes-cli.js - Create, edit, search, and manage notes programmatically
  • notes-export.js - Export notes to a flat directory structure
  • notes-export-with-folders.js - Export notes while preserving folder hierarchy

License

MIT

About

A Node.js tool to export Apple Notes to Markdown files with metadata preservation and folder structure mirroring

Resources

Stars

Watchers

Forks