From MS Word to RAG-Ready Markdown: Automating .docx ↔ Markdown Conversion on macOS with Pandoc and Automator (Markdown for Better Chunking)
261206
Introduction
If you write technical content, you probably live in two worlds. Colleagues, clients and managers send you Word documents (.docx). Your blog, your Git repositories, your documentation site and, more and more, your AI tools all prefer plain-text Markdown (.md).
Moving content between these two worlds by hand is tedious. Copy and paste breaks headings, lists and tables, images get lost, and you end up fixing formatting instead of writing. The good news is that the whole job can be automated with two free tools:
- Pandoc, a command-line “universal document converter”, does the actual conversion. It reads the Word file, understands its structure (headings, lists, tables, images, links) and writes the same structure out as Markdown, or the other way around.
- macOS Automator wraps a small Bash script around Pandoc and turns it into a Quick Action. That means the conversion lives in Finder’s right-click menu, so you never have to open Terminal or remember command-line options once it’s set up.
The end result looks like this: you right-click one or more .docx files in Finder, choose Quick Actions → Convert Word to Markdown, and a few seconds later a clean .md file (plus a folder with its images) appears next to each original. A second Quick Action, Convert Markdown to Word, does the reverse.
Why bother? Besides making blog publishing easier, clean Markdown is one of the best inputs for RAG (Retrieval-Augmented Generation) apps, the AI apps that answer questions from your own documents. Its headings give a RAG pipeline natural places to split a document into meaningful chunks, which leads to better search results and better answers. So the same right-click that prepares a blog post also makes your Word documents “RAG-ready”.
In this post we cover the background you need before building those actions:
- Markdown: what it is, why it matters for blogs and for RAG (Retrieval-Augmented Generation) apps, how it makes splitting documents into chunks easier, and which tools convert Word to Markdown.
- Pandoc: what it is, where it came from, why it is a great fit for
.docx↔ Markdown, and how to install it on a Mac the right way. - macOS Automator and Quick Actions: what they are, what they can do, and the general steps to turn a Bash script into a Finder right-click action.
The post is written for beginner to mid-level developers. You should be comfortable opening Terminal and running a command, but you don’t need to be a shell scripting expert. Every command is explained.
Section 1: Markdown
What is Markdown?
Markdown is a lightweight markup language for writing formatted text using plain text. It was created in 2004 by John Gruber, with input from Aaron Swartz, with one main goal: a Markdown file should be easy to read as is, even before it is rendered.
A few examples:
# A heading ## A smaller heading Some **bold** text, some *italic* text and `inline code`. - A bullet point - Another bullet point 1. A numbered step 2. Another step [A link](https://example.com) 
When rendered, # becomes a heading, **bold** becomes bold, and so on. The source stays readable either way. Compare that with HTML, where the same content is surrounded by opening and closing tags, or with a Word file, where you can’t read the content at all without Word.
The original Markdown specification left many edge cases undefined (for example, exactly how nested lists or blank lines inside lists should behave), so several “flavors” appeared. The two you will meet most often are:
- CommonMark: a strict, well-defined specification of the core syntax, published in 2014. Its goal is that the same Markdown file renders the same way in every tool that follows the spec. It comes with a detailed specification document and hundreds of test cases.
- GitHub Flavored Markdown (GFM): CommonMark plus a few practical extras, such as tables, task lists (
- [ ] todo), strikethrough (~~text~~) and automatic links for bare URLs. This is what GitHub uses, and many blogs, editors and converters support it too. When in doubt, GFM is a safe default.
Where is Markdown used?
Practically everywhere developers write text:
- Code repositories: almost every project on GitHub, GitLab or Bitbucket has a
README.md, and often aCHANGELOG.mdandCONTRIBUTING.md. These platforms render Markdown automatically, so the README becomes the project’s front page. - Documentation sites: tools such as MkDocs, Docusaurus, Sphinx (through the MyST extension), Read the Docs and GitBook build complete documentation websites from folders of Markdown files. Writers edit text files, and the tool handles navigation, search and styling.
- Static site generators and blogs: Hugo, Jekyll, Astro and Eleventy turn Markdown files into fast static websites. Ghost supports Markdown natively, and WordPress supports it through the block editor’s Markdown handling, plugins or the Jetpack Markdown block.
- Note-taking apps: Obsidian, Joplin, Bear and Logseq store notes as Markdown, and Notion can import and export it. Because the notes are plain files, you own them and can move them between apps.
- Chat and collaboration tools: Slack, Discord, Microsoft Teams, Jira and Confluence all understand at least part of the Markdown syntax for bold, italics, lists and code.
- Notebooks: the text cells in Jupyter notebooks are written in Markdown, which is how data scientists mix explanations with code and charts.
- AI tools: chatbots such as ChatGPT and Claude typically format their answers in Markdown, and many AI pipelines store their knowledge bases in it, as we’ll see next.
Why is Markdown important as a document source in RAG apps?
A RAG (Retrieval-Augmented Generation) app answers questions using your own documents. In a typical pipeline you:
- Ingest documents (Word files, PDFs, web pages…).
- Split them into smaller pieces called chunks.
- Embed each chunk (turn it into a vector, a list of numbers that captures its meaning) and store it in a vector database.
- At question time, retrieve the most relevant chunks and pass them to a large language model (LLM) as context, so it can answer based on your content instead of only its training data.
👉 See more about RAG apps: “How a typical RAG App Actually Works: A Step-by-Step Walkthrough for Your First Project”
The quality of the answers depends heavily on the quality of the chunks, and that is where Markdown shines:
- Structure survives. Headings (
#,##,###), lists and tables are kept as explicit, simple markers in the text. A program can see exactly where a section starts and ends, which is information that is hidden in Word’s XML styles and often completely lost in a PDF. - It’s clean text. There is no binary packaging, XML markup, fonts or layout information to strip out, so less noise ends up in the embeddings. Cleaner input means the vectors represent the meaning of the text, not formatting leftovers.
- It’s token-efficient. Markdown adds very few extra characters compared to HTML or XML. A heading costs one or two
#characters instead of<h2 class="...">...</h2>. More real content fits into the LLM’s context window, and since most LLM APIs charge per token, you also pay less. - LLMs understand it well. Models have seen huge amounts of Markdown during training (GitHub, documentation, forums), so they read its structure naturally. A table in Markdown is understood as a table, and a
##line is understood as a section title. - It’s easy to inspect and fix. If retrieval returns a weird chunk, you can open the
.mdfile in any editor, see exactly what the model saw and correct it. With.docxor.pdf, the text the model received is hidden behind a parser.
How Markdown makes chunking easier
Chunking is the step where most RAG pipelines quietly lose quality. The simplest approach, fixed-size chunking, cuts the text every N characters or tokens (for example every 1,000 characters, with a 200-character overlap). It’s easy, but it has no idea what the text is about. A cut can land in the middle of a sentence, split a table in two, separate a code block from the sentence that explains it, or glue the end of one topic to the start of the next. The resulting chunks mix ideas, so their embeddings are vague and retrieval gets worse.
👉 See more about Chunking: “Starting Your First RAG Project? Untangle These Confusing Terms First”
Markdown gives the chunker clear, reliable boundaries to cut on instead:
- Split by headings (structure-aware chunking). Each
#,##or###line marks the start of a section. A Markdown-aware splitter cuts the document at those lines, so every chunk is one complete section about one topic. If a section is still too long, it is split again at the next heading level down (###, then####), and only as a last resort at paragraph boundaries. - Keep the heading path as context. While splitting, the chunker records which headings each chunk sits under, for example
Installation > macOS > Homebrew. This “breadcrumb” can be stored as metadata or added to the top of the chunk text. A chunk that only says “Runbrew upgradeto update” becomes much easier to find, and to understand, when it carries the heading “Installation > macOS > Homebrew”. - Respect paragraphs and lists. Blank lines separate paragraphs, and list items start with
-,*or1.. A splitter can use these as secondary boundaries, so it never cuts in the middle of a sentence or a list item. - Keep code blocks and tables whole. Fenced code blocks (between
```lines) and tables (lines starting with|) are easy to detect. A good splitter treats each one as a single unit and keeps it together with the paragraph that introduces it. - Filter or route by section. Because every chunk knows its heading, you can do useful things at query time, such as searching only “Troubleshooting” sections or boosting chunks from “Overview” sections.
A small example. Given this Markdown:
# Pandoc Guide ## Installation ### macOS Install it with Homebrew: `brew install pandoc`. ### Windows Download the .msi installer from the releases page. ## Usage Convert a file with `pandoc input.docx -t gfm -o output.md`.
A heading-based splitter produces three clean chunks:
| Chunk | Heading path (metadata) | Text |
|---|---|---|
| 1 | Pandoc Guide > Installation > macOS | Install it with Homebrew: brew install pandoc. |
| 2 | Pandoc Guide > Installation > Windows | Download the .msi installer from the releases page. |
| 3 | Pandoc Guide > Usage | Convert a file with pandoc input.docx -t gfm -o output.md. |
Each chunk is about exactly one thing, and each one knows where it came from. A fixed-size splitter could easily have produced a chunk containing the end of the macOS instructions and the start of the Windows ones, which would confuse both retrieval and the LLM.
You don’t have to write this logic yourself. Popular RAG frameworks include Markdown-aware splitters, for example MarkdownHeaderTextSplitter in LangChain and MarkdownNodeParser in LlamaIndex. A common recipe is to split by headings first, then apply a size limit inside very long sections. Either way, the splitter can only be as good as its input: the cleaner and more consistent your Markdown headings are, the better your chunks. That’s exactly why a reliable Word-to-Markdown conversion step, which keeps Word’s Heading 1/2/3 styles as #, ## and ###, is worth automating.
In short: converting your source documents to good Markdown before ingestion is one of the cheapest ways to improve a RAG system.
Benefits of Markdown-converted documents compared to .docx and .pdf
Markdown (.md) | Word (.docx) | PDF (.pdf) | |
|---|---|---|---|
| File type | Plain UTF-8 text. What you see in the editor is exactly what’s stored on disk. | A ZIP archive containing XML files (text, styles, settings) plus images. You can unzip a .docx to see them. | A page-description format that places text, fonts and graphics at exact positions on fixed-size pages. |
| Readable without special software | Yes. Any text editor, terminal (cat), IDE or browser can show it. | Needs Word or a compatible app (Pages, LibreOffice, Google Docs). Opening the raw XML is possible but impractical. | Needs a PDF viewer. Viewers are everywhere, but the content is meant for viewing, not editing. |
| Structure (headings, lists, tables) | Explicit and simple: # for headings, - for lists, | for tables. Easy for both people and programs to detect. | Present, but stored as paragraph styles (e.g. “Heading 2”) buried in XML. Only preserved if the author actually used styles rather than bold, larger text. | Often lost. Text is stored as positioned fragments, so headings are just “bigger text” and tables are just text that happens to line up. |
| Version control (Git) and diffs | Excellent. Git shows exactly which lines changed, and merges and code reviews work naturally. | Poor. Git sees a binary file, so you can’t see what changed without special tools; Word’s tracked changes are the alternative. | Poor. Binary, and small text edits can change large parts of the file. |
| Text extraction for AI and search | Trivial. The file already is the text, with structure intact. | Needs a parser (Pandoc, python-docx, MarkItDown). Usually works well if the document uses proper styles. | Hard. Multi-column layouts, headers and footers, page numbers, hyphenation and tables often come out scrambled. Scanned PDFs even need OCR. |
| File size | Tiny. Typically a few kilobytes; images are kept as separate files. | Medium. Compressed XML plus embedded images and fonts. | Medium to large, especially with embedded fonts and high-resolution images. |
| Portability and longevity | Very high. Plain text will be readable in 30 years with any tool. | Good, but tied to the Office Open XML format and how each app interprets it; layouts can shift between Word, Pages and LibreOffice. | Very high for viewing (PDF/A is an archival standard), low for editing. |
| Publishing to the web | Direct. Blogs, docs sites, static site generators and GitHub render it as-is. | Needs conversion. Pasting Word content into a CMS often brings hidden inline styles and messy HTML. | Needs conversion, or embedding as a download/viewer, which is poor for SEO and mobile reading. |
To be fair, Markdown is not better at everything. Word and PDF are better at precise page layout, print-ready output, complex tables with merged cells, tracked changes and comments. Markdown wins when the content and its structure matter more than how the page looks, which is exactly the case for blogs, documentation and AI pipelines.
Why is .docx so popular for writing and authoring?
- It’s the default. Microsoft Word has been the standard word processor in offices, schools and governments for decades, and
.docx(Office Open XML, introduced with Office 2007) is its default format. Most people learned to write documents in Word, and most organizations have years of content and templates in it. - WYSIWYG editing. “What you see is what you get”: you see the final look while you type, with no syntax to learn. For non-technical authors this is the most natural way to write.
- Rich features. Styles, page layout, headers and footers, automatic tables of contents, footnotes and endnotes, citations and bibliographies, equations, and spelling and grammar checking. Word covers almost every need of a formal document.
- Review workflows. Comments and tracked changes let several people suggest edits and let the author accept or reject each one. Legal, academic and corporate teams rely heavily on this.
- Collaboration and compatibility. Real-time co-authoring in Microsoft 365, and
.docxopens in Google Docs, LibreOffice, Apple Pages and many other apps. It’s a format almost everyone can open. - Business expectations. Contracts, reports, proposals, CVs and official forms are often required to be delivered in Word format, so even people who prefer other tools end up producing
.docxfiles.
Why is Markdown popular for web blog posts?
- It’s fast to write. No toolbar clicking; your hands stay on the keyboard. After a day of practice, typing
##for a heading or**for bold becomes second nature. - It produces clean HTML. Markdown maps directly to simple, semantic HTML elements (
<h2>,<p>,<ul>,<code>), without the hidden inline styles, fonts and extra<span>tags that pasted Word content often brings along. Clean HTML is easier to style with your theme, loads faster and is friendlier to search engines. - It’s great for code. Fenced code blocks with language hints (
```bash) make syntax highlighting easy and keep indentation intact, which matters a lot for developer blogs. Word tends to “smart-quote” and reformat code, which breaks it when readers copy and paste. - It’s portable. The same
.mdfile can go to WordPress, Ghost, Hugo, dev.to, Hashnode or GitHub with little or no change. You are not locked into one platform, and moving your blog later is much easier. - It fits a developer workflow. Posts can live in Git, be reviewed in pull requests, be checked by linters and spell-checkers, and be built and published automatically by static site generators and CI pipelines.
- You can write anywhere. Any editor works: VS Code, Sublime Text, Obsidian, iA Writer, or even a phone notes app. Your drafts are plain files you own.
Well-known tools for converting .docx to Markdown
- Pandoc: the free, open-source command-line converter this post is built around. It handles headings, lists, tables, footnotes, links and images, supports several Markdown flavors and works in both directions. Covered in detail in Section 2.
- Microsoft MarkItDown: an open-source Python tool and library from Microsoft that converts Word, PowerPoint, Excel, PDF, HTML, images and more into Markdown. It was designed mainly for feeding LLM and RAG pipelines, so it focuses on preserving structure for machines rather than perfect visual fidelity for humans. Install it with
pipand run it from the command line or from Python code. - Docling: an open-source document-conversion toolkit (originally from IBM Research) that turns PDF, DOCX, PPTX, HTML and images into Markdown or JSON. Its strength is layout understanding: it uses AI models to detect reading order, tables and figures, which makes it especially good for difficult PDFs. Popular in AI pipelines and integrated with frameworks like LangChain and LlamaIndex.
- Mammoth: a JavaScript and Python library that converts
.docxto clean, semantic HTML by mapping Word styles to HTML elements, ignoring visual formatting. The HTML can then be turned into Markdown, for example with the Turndown library. Handy inside web apps that accept Word uploads. - Google Docs: if you prefer a no-install option, open the
.docxin Google Docs and use File → Download → Markdown (.md). Good for occasional, one-off conversions, but not easy to automate and images are not exported as separate files. - Writage: a plugin for Microsoft Word on Windows that adds Markdown as an “Open” and “Save As” format inside Word itself. Useful for teams who want to keep writing in Word but store the result as Markdown.
- Online converters: many web-based “Word to Markdown” sites exist. They are fine for a quick, non-sensitive document, but your file is uploaded to someone else’s server, so avoid them for anything confidential.
Section 2: Pandoc
What is Pandoc?
Pandoc describes itself as a “universal document converter”, and the name fits. It is a free, open-source command-line program that reads a document in one markup format and writes it in another.
A short history. Pandoc was created by John MacFarlane, a philosophy professor at the University of California, Berkeley, and was first released in 2006. It is written in Haskell and is developed in the open on GitHub (jgm/pandoc) with many contributors. MacFarlane is also one of the main people behind CommonMark, the standard Markdown specification, so Pandoc’s Markdown support is in very good hands. Pandoc 3.0 arrived in January 2023, and the 3.x series is still being actively released several times a year.
How it works. Pandoc doesn’t convert format A directly to format B. Instead it:
- Reads the input into an internal, format-neutral document tree (its “AST”, or abstract syntax tree). In that tree, a heading is just “a level-2 heading with this text”, regardless of whether it came from Word, HTML or Markdown.
- Optionally runs filters (in Lua or other languages) that can inspect and change that tree, for example to adjust image sizes, rename styles or remove unwanted elements.
- Writes the tree out in the target format.
This design is why Pandoc can support so many formats: adding a new format only means writing one new reader or writer, not a converter for every possible pair.
Supported formats (a selection). Pandoc reads and writes dozens of formats, including:
- Markdown flavors: Pandoc’s own extended Markdown (with footnotes, citations, definition lists and more), CommonMark, GitHub Flavored Markdown (GFM), MultiMarkdown and PHP Markdown Extra.
- Office and e-books: Word (
.docx) and OpenDocument (.odt) in both directions, RTF, and EPUB e-books. PowerPoint (.pptx) is supported as output, so you can turn a Markdown outline into a slide deck. - Web: HTML in both directions, plus HTML slide shows such as reveal.js and Slidy.
- Technical and lightweight markup: LaTeX, reStructuredText (used by Python’s documentation), AsciiDoc (output), Emacs Org mode, Textile, MediaWiki and DokuWiki wiki syntax, Typst, Jupyter notebooks (
.ipynb), DocBook and JATS (used in scientific publishing). - PDF: as output only. Pandoc hands the document to a PDF engine such as LaTeX, Typst or an HTML-to-PDF tool to produce the final file.
Note that Pandoc cannot read PDF files. For PDF to Markdown, use a tool such as Docling or MarkItDown. Also, old binary .doc files (Word 97–2003) are not supported: open them in Word and save them as .docx first.
You can always see the exact lists for your installed version with:
pandoc --list-input-formats pandoc --list-output-formats
Where is it used? Pandoc is a quiet workhorse behind a lot of tooling:
- Academic writing: researchers write papers and theses in Markdown, manage citations with a bibliography file, then export to Word for co-authors, LaTeX for journals or PDF for submission, all from the same source.
- R Markdown and Quarto (from Posit) use Pandoc under the hood to turn notebooks with code and results into reports, books, slides and websites.
- Documentation and technical publishing: manuals, books and e-books are often written in Markdown and published to HTML, EPUB and PDF with Pandoc in a build script.
- Content migrations: moving content between wikis, CMSs and blogs, for example from MediaWiki or HTML to Markdown, or from Markdown to Word for a client.
- AI and data pipelines: converting document collections into Markdown or plain text before indexing them for search or RAG.
Why Pandoc might be the preferred tool for .docx → Markdown
- Free, open source and offline. Your documents never leave your machine, which matters for confidential material like contracts, internal reports or client documents. There are no accounts, limits or subscriptions.
- High fidelity for document structure. Word headings become
#headings, bold and italics are kept, numbered and bulleted lists stay lists, links stay links, footnotes and tables are converted properly. You get real Markdown structure, not just flattened text. - Images are extracted. With
--extract-media, embedded images are saved as real image files in a folder and linked from the Markdown with relative paths, so the.mdand its images can be moved or published together. - You choose the Markdown flavor. Output GFM for GitHub and most blogs (
-t gfm), Pandoc’s own extended Markdown when you need footnotes, captions and other extras (-t markdown), or strict CommonMark for maximum compatibility (-t commonmark). - Two-way conversion. The same tool converts Markdown back to
.docx. It can even use a “reference” Word document (--reference-doc) so the output automatically uses your company’s fonts, colors and heading styles. - Scriptable. It is a single command-line program with predictable options and exit codes, which makes it perfect for automation with Bash scripts, Makefiles, CI pipelines and, as we’ll see, macOS Quick Actions. Converting one file or a thousand files is the same command in a loop.
- Customizable. Lua filters let you fix edge cases (for example, keeping image sizes, or turning certain Word styles into special Markdown blocks) without changing Pandoc itself.
- Mature and maintained. Nearly two decades of development, frequent releases, thorough documentation and a large, active user community, so most problems you meet already have an answer online.
A basic conversion is a one-liner:
pandoc Report.docx -f docx -t gfm --wrap=none --extract-media=Report_media -o Report.md
-f docx: the input format (“from”), here Word. Pandoc can usually guess it from the file extension, but being explicit is clearer in scripts.-t gfm: the output format (“to”), here GitHub Flavored Markdown.--wrap=none: don’t hard-wrap long lines. By default Pandoc wraps text at 72 characters; keeping each paragraph on one line is better for blogs and for RAG chunking.--extract-media=Report_media: save embedded images into that folder and link to them from the Markdown.-o Report.md: the output file. Without-o, Pandoc prints the result in the terminal.
And the reverse:
pandoc Report.md -f gfm -t docx -o Report.docx
How to install Pandoc on a Mac
You have two main options.
Option A: the official installer. Download the macOS .pkg from the Pandoc releases page on GitHub (linked from pandoc.org) and run it like any other installer. It works, but you’ll have to repeat the process manually for every update.
Option B (recommended): Homebrew. Homebrew is the most popular package manager for macOS: a command-line tool that installs, updates and removes developer software for you.
- Open Terminal (⌘ Space, type “Terminal”, press Return).
- If you don’t have Homebrew yet, copy the install command from brew.sh, paste it into Terminal and follow the prompts. At the end, Homebrew prints a “Next steps” section with one or two commands that add it to your
PATH. Run them, otherwise your shell won’t find thebrewcommand. - Install Pandoc:
brew install pandoc - Check that it works:
pandoc --version which pandocpandoc --versionprints the installed version. On an Apple Silicon Mac (M1 and later),which pandocshould print/opt/homebrew/bin/pandoc. On older Intel Macs, Homebrew uses/usr/local/bin/pandoc. Remember this path: we’ll need it when we build the Quick Action.
Why installing via Homebrew is preferable
- Easy updates.
brew upgrade pandoc(or justbrew upgradefor everything) keeps you on the latest release, with bug fixes and better format support. With the.pkginstaller you have to notice that a new version exists, then download and reinstall it manually. - Clean uninstall.
brew uninstall pandocremoves it completely. Files installed by a.pkgare spread across system folders, and macOS has no built-in “uninstall” for them. - One predictable location. All your Homebrew tools live under
/opt/homebrew(Apple Silicon). That matters for automation: scripts, and Automator in particular, run with a very minimalPATH, so it helps to know exactly where your tools are and add that one folder. - Native Apple Silicon builds. Homebrew installs a build made for your Mac’s processor, so it runs natively instead of through the Rosetta translation layer.
- Avoids duplicate copies. Mixing installation methods can leave two Pandoc versions on your system, one updated and one not, and it isn’t always obvious which one a script will run. Sticking to Homebrew avoids that confusion.
- The same tool for everything else. Homebrew is the de facto package manager for developers on macOS, so you manage Pandoc the same way as Git, Node, Python, ImageMagick and the rest of your tools. One command (
brew list) shows everything you’ve installed.
Section 3: The macOS Automator Tool
What is Automator?
Automator is Apple’s built-in visual automation app. It has shipped with macOS since Mac OS X 10.4 Tiger (2005) and you’ll find it in your Applications folder (its icon is a robot holding a pipe).
Instead of writing a program, you build a workflow by dragging actions from a library into a list. Each action does one thing (for example, “Get Selected Finder Items”, “Rename Finder Items” or “Run Shell Script”) and passes its result to the next one, a bit like a Unix pipeline with a graphical interface. You can run the workflow inside Automator to test it and see the result of each step.
Apple’s newer Shortcuts app (on the Mac since macOS Monterey, 2021) is positioned as the long-term successor. However, Automator is still included in current macOS versions, it is still the simplest way to create Finder Quick Actions that run shell scripts, and existing workflows keep working.
What can Automator do?
- Work with files and folders: rename hundreds of files in one go (add dates, numbers or replace text), move or copy them, filter them by name, kind or date, and create ZIP archives.
- Work with images and PDFs: resize and scale images, convert between formats (for example HEIC to JPEG or PNG), rotate and flip, combine several PDFs into one, extract pages, and add watermarks.
- Control apps: automate tasks in Finder, Mail, Calendar, Music, Photos, Preview, Safari and any other app that supports AppleScript, such as creating emails with attachments or importing photos into an album.
- Work with text: read text from files or the clipboard, filter and combine it, and save it to new files or speak it aloud.
- Run scripts: run shell scripts (Bash, zsh, Python and others) with the Run Shell Script action, and AppleScript or JavaScript with Run AppleScript and Run JavaScript. This is the bridge between friendly macOS menus and any command-line tool, including Pandoc. Anything you can do in Terminal, you can put behind a menu item.
- Record actions: the “Watch Me Do” feature records mouse clicks and keystrokes and plays them back. It’s useful for apps that have no other automation support, but fragile, because it breaks if a window or button moves.
Automator can save a workflow as several document types:
| Type | What it does |
|---|---|
| Workflow | A workflow you run from inside Automator itself. Good for testing, or for tasks you run only occasionally and want to watch step by step. |
| Application | A standalone app you can keep in the Dock or on the Desktop. Double-click it to run, or drop files onto its icon to process them. |
| Quick Action (formerly Service) | Appears in Finder’s right-click menu under Quick Actions, at the bottom of the Finder Preview pane, on the Touch Bar and in the Services menu of apps. It works on whatever you have selected: files, folders, text or images. This is the type we’ll use. |
| Folder Action | Attached to a specific folder and runs automatically whenever files are added to it, for example “resize every image dropped into this folder”. |
| Print Plugin | Appears in the PDF menu of the Print dialog, so you can process a document as part of printing, for example “save as PDF and email it”. |
| Calendar Alarm | Runs at a scheduled time, triggered by an event in the Calendar app. A simple way to schedule recurring tasks. |
| Image Capture Plugin | Processes photos and scans right after you import them with the Image Capture app, for example renaming or resizing them. |
| Dictation Command | Runs when you speak a chosen phrase (available on older macOS versions). |
Where is Automator used most?
In practice, people mostly use Automator for:
- Repetitive file chores: batch renaming photos or scanned documents, sorting the Downloads folder, converting a folder of images to another format or size. Tasks that take minutes by hand take seconds.
- Right-click helpers (Quick Actions): small one-click tools such as “Convert to PDF”, “Resize image”, “Open in VS Code”, “Copy file path” and, in our case, “Convert Word to Markdown”. This is probably the most popular use today.
- Folder Actions that watch a folder and process anything dropped into it automatically, for example a “To Markdown” folder where every
.docxyou drop in gets converted. - Wrapping command-line tools (like Pandoc, ImageMagick or ffmpeg) so non-technical colleagues, or your future self, can use them without opening Terminal or remembering options.
What is the right-click context menu in macOS?
The context menu is the menu that appears when you right-click (or Control-click, or two-finger click on a trackpad) on something. Its contents depend on what you clicked, hence “context”: right-clicking a file, a folder, a piece of selected text or an empty area of the Desktop each shows different commands.
In Finder, right-clicking a file shows commands like Open, Open With, Get Info, Rename, Compress, Duplicate, Copy, Share, Tags and, near the bottom, Quick Actions. It’s the fastest way to act on a file without first opening an app, which is exactly why it’s the perfect home for our converter.
What are Quick Actions?
Quick Actions are small, reusable tasks you can run on selected items without opening an app. In Finder you’ll find them:
- In the right-click menu, under the Quick Actions submenu.
- At the bottom of the Finder Preview pane (View → Show Preview), as small buttons for the selected file.
- On the Touch Bar, on MacBook models that have one.
macOS includes a few built-in ones, such as Rotate, Markup, Create PDF, Convert Image and Remove Background (which ones appear depends on your macOS version and the type of file you selected). You can add your own with Automator or the Shortcuts app, and they appear in the same submenu next to Apple’s.
Quick Actions replaced what older macOS versions called Services. Since macOS Mojave (2018) they are called Quick Actions in Finder, but they are still stored the same way: as .workflow bundles in ~/Library/Services/. You may still see them in the Services submenu of some apps.
Quick Actions can be turned on and off in System Settings → General → Login Items & Extensions → Extensions → Finder (on older versions: System Settings → Privacy & Security → Extensions → Finder). This is also where to look if one of your Quick Actions doesn’t appear in the menu.
General steps: turning a Bash script into a Quick Action
Here is the general recipe. In the next part of this series we’ll apply it to the actual Word ↔ Markdown scripts.
1. Write and test the script in Terminal first.
Make sure the core command works before adding Automator to the mix. It’s much easier to debug in Terminal, where you can see error messages. For example:
pandoc "My Report.docx" -t gfm --wrap=none -o "My Report.md"
2. Create a new Quick Action in Automator.
Open Automator → New Document → Quick Action → Choose.
3. Tell the Quick Action what it receives.
At the top of the workflow set:
- Workflow receives current:
files or folders. This makes the action appear when you right-click files in Finder. - in:
Finder.app(orany application). Limiting it to Finder keeps it out of other apps’ menus. - Optionally pick an Image (icon) and Color, which are shown in the Preview pane and on the Touch Bar.
4. Add a “Run Shell Script” action.
Type “Run Shell Script” in the library search box and drag the action into the workflow area. Then set:
- Shell:
/bin/bash. Choose the shell your script is written for. - Pass input:
as arguments. With this setting, the selected files arrive in your script as$1,$2, …, and you can loop over all of them with"$@". The other option, “to stdin”, sends the file paths as lines of text instead.
5. Paste your script, adapted for Automator.
A minimal skeleton looks like this:
# Automator runs scripts with a minimal PATH,
# so add Homebrew's locations explicitly
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
for f in "$@"; do
dir="$(dirname "$f")"
name="$(basename "$f")"
base="${name%.*}"
# Work inside the file's folder so relative paths stay relative
( cd "$dir" && pandoc "$name" -t gfm --wrap=none -o "${base}.md" )
done
# Optional: show a notification when done
osascript -e 'display notification "Done" with title "My Quick Action"'
Three things are worth remembering when moving a script from Terminal into Automator:
PATHis minimal. Automator doesn’t load your~/.zshrcor~/.bash_profile, sopandocwon’t be found unless you add/opt/homebrew/bintoPATHor use the full path. This is the number one reason a script that works in Terminal “does nothing” as a Quick Action.- Always quote your variables (
"$f","$@"). File names with spaces, likeMy Report.docx, are common on a Mac, and unquoted variables would split them into separate words. - There is no Terminal window. You won’t see errors, so write them to a log file (for example
~/Library/Logs/my-action.log, which you can open in the Console app) and/or show a notification withosascriptso you know the action finished.
6. Save it.
File → Save and give it the name you want to see in the menu, for example Convert Word to Markdown. Automator saves it automatically to ~/Library/Services/; there’s no need to choose a location.
7. Use it.
In Finder, select one or more files, right-click and choose Quick Actions → Convert Word to Markdown. The first time, macOS may ask for permission to access folders like Desktop or Documents. Click OK, or the script won’t be able to read or write files there.
8. Edit or remove it later.
Open ~/Library/Services/Convert Word to Markdown.workflow in Automator to edit it, or delete the file to remove the Quick Action. (In Finder, press ⌘⇧G and type ~/Library/Services to get there quickly.)
If the action doesn’t show up in the menu, check that it is enabled under the Finder extensions in System Settings, as described above.
Word → Markdown Quick Action for Finder
1. Create the Quick Action in Automator
1. Open Automator (in Applications, or via Spotlight).

2. Choose Quick Action → Choose.

3. At the top of the workflow set:
Workflow receives current: files or folders
in: Finder.app
(Optional) Image: pick an icon you like.

4. In the left library search box type Run Shell Script and drag it into the workflow area.

4. In the Run Shell Script action set:
Shell: /bin/bash
Pass input: as arguments

5. Delete the placeholder text and paste the whole script from section 3 below.

6. File → Save, name it Convert Word to Markdown.
That’s it. Automator saves it to ~/Library/Services/.
3. The script
# Word (.docx) -> Markdown Quick Action
# Automator: Shell = /bin/bash, Pass input = as arguments
# Automator runs with a minimal PATH, so add Homebrew's locations
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
PANDOC="$(command -v pandoc)"
if [ -z "$PANDOC" ]; then
osascript -e 'display alert "Pandoc not found" message "Install it in Terminal with: brew install pandoc"'
exit 1
fi
LOG="$HOME/Library/Logs/docx2md.log"
ok=0
fail=0
last=""
for f in "$@"; do
name="$(basename "$f")"
# Only .docx files (any letter case); skip Word's ~$ lock files
case "$(printf '%s' "$name" | tr '[:upper:]' '[:lower:]')" in
'~$'*) continue ;;
*.docx) ;;
*) continue ;;
esac
dir="$(dirname "$f")"
base="${name%.*}"
# Run inside the file's folder so image links in the .md are relative
if ( cd "$dir" && "$PANDOC" "$name" -f docx -t gfm --wrap=none \
--extract-media="${base}_media" -o "${base}.md" ) 2>>"$LOG"; then
ok=$((ok + 1))
last="${base}.md"
else
fail=$((fail + 1))
echo "$(date): failed on $f" >>"$LOG"
fi
done
if [ "$ok" -eq 1 ] && [ "$fail" -eq 0 ]; then
msg="Created $last"
elif [ "$fail" -eq 0 ]; then
msg="Converted $ok file(s) to Markdown"
else
msg="Converted $ok, failed $fail (see ~/Library/Logs/docx2md.log)"
fi
osascript - "$msg" <<'APPLESCRIPT'
on run argv
display notification (item 1 of argv) with title "Word → Markdown"
end run
APPLESCRIPT
3. Use it
Right-click one or more .docx files in Finder → Quick Actions → Convert Word to Markdown. For each file you get:
Report.mdnext to the original (GitHub-flavored Markdown, no hard line wrapping)Report_media/media/…with any images, linked from the.mdwith relative paths (only created if the document has images)- A notification when it’s done
Notes: an existing .md with the same name is overwritten. Old .doc files aren’t supported by Pandoc, so save them as .docx first. Errors are logged to ~/Library/Logs/docx2md.log.
The first run may ask to allow Finder/Automator to access the folder (e.g. Desktop or Documents). Click OK.
Troubleshooting
- “Pandoc not found” alert: run
brew install pandocin Terminal, then try again. - Quick Action not in the menu: System Settings → General → Login Items & Extensions → Extensions → Finder (on older macOS: System Settings → Privacy & Security → Extensions → Finder) and make sure Convert Word to Markdown is ticked.
- Nothing happens / some files failed: check
~/Library/Logs/docx2md.log. - Edit or remove it later: open
~/Library/Services/Convert Word to Markdown.workflowin Automator, or delete that file.
Tweaks
One shared images folder instead of one per document: change --extract-media="${base}_media" to --extract-media=. (images go into media/, but files from different documents may overwrite each other).
Different Markdown flavor: change -t gfm to -t markdown (Pandoc’s own, keeps more formatting like footnotes and tables with captions) or -t commonmark.
Keep line wrapping at 72 characters: remove --wrap=none.
Markdown → Word Quick Action for Finder
This is the reverse of Convert Word to Markdown, so no need for screenshots.
1. Create the Quick Action in Automator
- Open Automator → New Document → Quick Action → Choose.
- At the top set Workflow receives current:
files or folders, in:Finder.app. - Drag in Run Shell Script (search for it in the left library).
- Set Shell:
/bin/bashand Pass input:as arguments. - Delete the placeholder text and paste the whole script from section 2.
- File → Save, name it
Convert Markdown to Word.
2. The script
# Markdown (.md) -> Word (.docx) Quick Action
# Automator: Shell = /bin/bash, Pass input = as arguments
# Automator runs with a minimal PATH, so add Homebrew's locations
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
PANDOC="$(command -v pandoc)"
if [ -z "$PANDOC" ]; then
osascript -e 'display alert "Pandoc not found" message "Install it in Terminal with: brew install pandoc"'
exit 1
fi
LOG="$HOME/Library/Logs/md2docx.log"
# Small Pandoc filter: keep picture sizes written as style="width:..;height:.."
FILTER="${TMPDIR:-/tmp}/md2docx_$$.lua"
trap 'rm -f "$FILTER"' EXIT
cat > "$FILTER" <<'LUA'
function Image(img)
local style = img.attributes.style
if style then
local w = style:match("width:%s*([%d%.]+%a*)")
local h = style:match("height:%s*([%d%.]+%a*)")
if w then img.attributes.width = w end
if h then img.attributes.height = h end
img.attributes.style = nil
end
return img
end
LUA
ok=0
fail=0
last=""
for f in "$@"; do
name="$(basename "$f")"
case "$(printf '%s' "$name" | tr '[:upper:]' '[:lower:]')" in
*.md|*.markdown) ;;
*) continue ;;
esac
dir="$(dirname "$f")"
base="${name%.*}"
# Never overwrite an existing Word file (e.g. the original .docx):
# use "Name.docx", else "Name (2).docx", "Name (3).docx", ...
out="${base}.docx"
n=2
while [ -e "$dir/$out" ]; do
out="${base} ($n).docx"
n=$((n + 1))
done
# Go through HTML so <img> tags (which the Word->Markdown action writes
# for sized images) become real embedded pictures, not dropped raw HTML.
# Run inside the file's folder so relative image paths (Name_media/...) resolve.
if ( cd "$dir" && set -o pipefail && \
"$PANDOC" "$name" -f gfm -t html --resource-path=. | \
"$PANDOC" -f html -t docx --resource-path=. --lua-filter="$FILTER" -o "$out" ) 2>>"$LOG"; then
ok=$((ok + 1))
last="$out"
else
fail=$((fail + 1))
rm -f "$dir/$out"
echo "$(date): failed on $f" >>"$LOG"
fi
done
if [ "$ok" -eq 1 ] && [ "$fail" -eq 0 ]; then
msg="Created $last"
elif [ "$fail" -eq 0 ]; then
msg="Converted $ok file(s) to Word"
else
msg="Converted $ok, failed $fail (see ~/Library/Logs/md2docx.log)"
fi
osascript - "$msg" <<'APPLESCRIPT'
on run argv
display notification (item 1 of argv) with title "Markdown → Word"
end run
APPLESCRIPT
3. Use it
Right-click one or more .md files in Finder → Quick Actions → Convert Markdown to Word. For each file you get:
- A Word file next to the
.md, with images from theName_mediafolder (or any other relative image path) embedded and their sizes kept - A notification when it’s done
It never overwrites an existing Word file. If Report.docx already exists (for example the original you converted from), it writes Report (2).docx, then Report (3).docx, and so on.
Errors are logged to ~/Library/Logs/md2docx.log. Pandoc is already installed, so there is nothing to install.
Why it goes through HTML
The Word → Markdown action writes sized images as HTML <img> tags. If Pandoc converted Markdown straight to Word, it would silently drop those images. The script converts to HTML first, which turns them into real pictures, and the small built-in filter keeps their width and height.
Tweaks
- Use your own Word styles (fonts, heading colors, margins): make a
.docxstyled the way you like, save it as e.g.~/Documents/reference.docx, and add--reference-doc="$HOME/Documents/reference.docx"after-t docxin the script. - Add a table of contents: add
--tocafter-t docx. - Overwrite instead of numbering: delete the
while … doneloop.
Key Takeaways
- Markdown is plain text with structure. Headings, lists, tables and code are written with a few simple symbols, so the same file is easy for people to read, for Git to track and for programs to process.
- Word and Markdown each have their place.
.docxis the standard for authoring, reviewing and sharing formal documents; Markdown is the better format for blogs, documentation, version control and AI pipelines. Converting between them lets you use the right format for each job without retyping anything. - Markdown makes RAG apps better. Clean, token-efficient text and explicit headings mean less noise in your embeddings and more useful content in the LLM’s context window.
- Headings are natural chunk boundaries. Splitting Markdown by
#,##and###, keeping each chunk’s heading path as metadata, and keeping tables and code blocks whole gives you focused, self-contained chunks, and that leads to better retrieval and better answers than cutting text every N characters. - Pandoc is the workhorse. It is free, open source, runs offline, keeps document structure and images, supports many Markdown flavors and converts in both directions. On a Mac, install it with Homebrew (
brew install pandoc) for easy updates and a predictable location in/opt/homebrew/bin. - Automator turns a script into a right-click. A Quick Action with a Run Shell Script step puts your Pandoc command in Finder’s context menu. Remember the three rules: set
PATHexplicitly, quote every variable, and log errors because there’s no Terminal window. - The payoff: once it’s set up, turning any Word document into blog-ready, RAG-ready Markdown, or back into Word, is a single right-click.
That’s it for now! I hope you enjoyed it!
Thanks for reading and stay tuned!
