Skip to content

Instantly share code, notes, and snippets.

@orip
Created June 28, 2026 16:24
Show Gist options
  • Select an option

  • Save orip/7cdc1237fe6cdea3ac6139fb9c36a3bb to your computer and use it in GitHub Desktop.

Select an option

Save orip/7cdc1237fe6cdea3ac6139fb9c36a3bb to your computer and use it in GitHub Desktop.
Copy markdown as HTML to the macOS clipboard - for pasting into Slack etc
#!/bin/bash
# Copy GitHub-Flavored Markdown as HTML into the Mac clipboard, allowing
# applications like Slack to paste the HTML.
#
# Requires pandoc for the markdown->HTML conversion (`brew install pandoc`)
#
# Copyright (c) 2026 Ori Peleg. Licensed under the MIT License.
# Usage: paste or pipe markdown into stdin
if ! command -v pandoc &> /dev/null; then
echo 'Error: pandoc is required but not found in PATH (try `brew install pandoc`). Aborting.' >&2
exit 1
fi
# read from stdin
markdown=$(cat)
# convert GFM -> HTML
html=$(echo "$markdown" | pandoc --from gfm --to html)
# Use macOS's JavaScript for Automation to load both string and html into the pasteboard (Slack looks for the HTML)
osascript -l JavaScript - "$markdown" "$html" <<'EOF'
function run(argv) {
ObjC.import('AppKit');
const pb = $.NSPasteboard.generalPasteboard;
pb.clearContents;
// Set markdown as string, html as html
pb.setStringForType(argv[0], $.NSPasteboardTypeString);
pb.setStringForType(argv[1], $.NSPasteboardTypeHTML);
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment