Skip to content

Instantly share code, notes, and snippets.

@koke
Created February 25, 2026 10:30
Show Gist options
  • Select an option

  • Save koke/b2f895adce3bd1847803b6917be831a9 to your computer and use it in GitHub Desktop.

Select an option

Save koke/b2f895adce3bd1847803b6917be831a9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Copy markdown from stdin as rich text to the macOS clipboard.
# Pasting into Slack, Mail, etc. preserves formatting and clickable links.
# Requires: pandoc (brew install pandoc)
set -euo pipefail
if [ -t 0 ]; then
echo "Usage: echo '**bold** [link](url)' | md2clipboard" >&2
exit 1
fi
html=$(pandoc -f markdown -t html)
hex=$(echo -n "$html" | hexdump -ve '1/1 "%.2x"')
printf 'set the clipboard to {text:" ", «class HTML»:«data HTML%s»}' "$hex" | osascript -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment