A robust AppleScript for macOS that extracts selected emails from Apple Mail and converts them into beautifully formatted Markdown (.md) files.
Unlike standard conversion scripts that strip all formatting, this script uses a CSS-injected HTML wrapper to ensure that email layouts, signatures, and line breaks are preserved exactly as they appear in Mail.
- Layout Preservation: Uses
white-space: pre-wrapCSS to prevent the common "wall of text" issue. - Smart Linkification: Automatically identifies "naked" URLs (like
google.com) and turns them into clickable links without breaking existing HTML tags. - Obsidian Ready: Automatically generates YAML frontmatter, including titles, dates, and nested tags.
- Deep Linking: Includes a
message://URI link in the header to jump back to the original email in Mail instantly. - Dynamic ID Fetching: Uses a runtime bypass to access the
html bodyproperty, avoiding common AppleScript compiler "Unknown Identifier" errors.
Before running the script, you must configure two primary variables at the top of the file:
AppleScript uses the HFS (Macintosh) path format (using colons : instead of slashes /).
Example of a fake path for your configuration:
-- Correct HFS Format:
property saveFolder : "Macintosh HD:Users:YourName:Documents:Notes:Emails:Archive:"
The tagList variable allows you to define Obsidian-style tags that will be added to every exported email. These are formatted as a comma-separated string and will be converted into a proper YAML list.
Example:
property tagList : "Function/Type/Email, Focus/Work, Project/Alpha"
Open the script in Script Editor, select one or more emails in Apple Mail, and hit Run.
Wrap this script in an Automator Quick Action. This allows you to right-click an email and select "Export to Markdown" from the context menu.
Set up a Mail Rule (Settings > Rules) to trigger this script automatically based on patterns (e.g., from specific senders or containing specific keywords) to automate your archival process.
Download the email-to-obsidian.scpt to your system. You can then set up the script as above in Usage Models.
This project is licensed under the MIT License. You are free to use, copy, modify, merge, publish, and distribute this software. For the full legal text, please visit the Open Source Initiative (OSI) MIT License page.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create.
- Bugs & Feature Requests: If you encounter a bug or have a feature request, please open a formal report in the Issues section.
- Questions & General Discussion: For new ideas, setup help, or sharing your workflow, please use the Discussions section.
- Code Improvements: If you modify the script or optimize the Regex logic further, please open a Pull Request so that everyone can benefit from your changes!