Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clip2md

Copy rich text anywhere on macOS, get clean Markdown on your clipboard.

Select text in a browser, Notion, Word, Mail — press your hotkey — paste Markdown. Headings, links, lists, bold and italics survive. No web service, no upload, nothing leaves your machine.

Why

macOS has no built-in way to convert formatted text to Markdown. The usual workarounds are online converters (which means pasting your content into someone else's server) or a browser extension that only works in the browser. clip2md is a 50-line shell script that works in every app.

Requirements

  • macOS
  • pandocbrew install pandoc

Install

git clone https://github.com/tillheidrich/clip2md.git
cd clip2md
./install.sh

This copies the script to /usr/local/bin/clip2md. Use a different location with PREFIX=~/bin ./install.sh.

Grant Accessibility permission

clip2md presses ⌘C for you, which macOS treats as controlling your computer. Without permission the script silently converts whatever was already on the clipboard instead of your selection.

Open System Settings → Privacy & Security → Accessibility and enable the app that runs the script — your terminal, Raycast, Shortcuts, Automator or Stream Deck. The exact entry depends on how you trigger it (see below).

Bind it to a hotkey

clip2md is a plain command, so anything that can run a shell command works.

Raycast / Alfred — add a script command that runs clip2md.

Shortcuts — new shortcut, add Run Shell Script with clip2md, assign a keyboard shortcut in the shortcut's settings.

Automator Quick Action — new Quick Action, Run Shell Script, input "no input", body clip2md. Then assign a key under System Settings → Keyboard → Keyboard Shortcuts → Services.

Stream Deck — use a System → Open action pointing at a small .app wrapper, or the Terminal plugin.

Configuration

Variable Default Meaning
CLIP2MD_TIMEOUT_MS 2000 How long to wait for the copy to land before converting. Raise it for slow apps.
CLIP2MD_TIMEOUT_MS=4000 clip2md

How it works

  1. Remember the current clipboard.
  2. Send ⌘C to copy the selection.
  3. Poll until the clipboard actually changes, or the timeout expires — rather than guessing a fixed sleep.
  4. Read the public.html flavour of the clipboard and run it through pandoc (gfm, unwrapped).
  5. If there is no HTML flavour, keep the plain text unchanged.
  6. Write the result back to the clipboard.

Because step 2 is a no-op when nothing is selected, running clip2md with an empty selection converts whatever is already on the clipboard. That is intentional and useful.

Limitations

  • Images become Markdown image references pointing at the original URLs. The files themselves are not downloaded.
  • Complex tables and nested layouts come out as pandoc renders them, which is usually good but not always pretty.
  • If the copied selection is byte-identical to the previous clipboard content, the script waits the full timeout before continuing. The output is still correct, just slower.

License

MIT — see LICENSE.

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages