Skip to content

pbrich: Copy Anything to the macOS Clipboard

macOS ships with pbcopy, a command-line tool for copying text to the clipboard. It’s been around for decades. But it only handles plain text.

Want to copy an image to the clipboard from the terminal? Can’t do it. Want to copy HTML so it pastes as a clickable link in Slack? No built-in way. Want to copy a PDF? Nope.

I ran into this when building a Keyboard Maestro macro to copy GitHub PR titles as clickable links. I needed to put HTML on the clipboard so Slack would render it as a rich link instead of raw <a> tags. After trying every approach (AppleScript RTF conversion, NSPasteboard via JXA, clipboard APIs), none of them worked reliably.

So I built pbrich.

How it works

pbrich reads from stdin, just like pbcopy. The difference is it can write to any pasteboard type.

Plain text (drop-in pbcopy replacement):

echo "hello" | pbrich

Copy an image. It auto-detects the format from the content:

cat screenshot.png | pbrich

Paste it into Slack, email, Notion, anywhere. It just works.

Copy a clickable link:

echo '<a href="https://example.com">My Link</a>' | pbrich -t public.html -p "https://example.com"

The -p flag sets a plain text fallback so apps that don’t support HTML still get something useful.

Auto-detection

pbrich reads the first few bytes of stdin to detect the content type. PNG, JPEG, PDF, TIFF, and RTF all have distinct magic bytes at the start of the file. If it recognizes the format, it sets the correct pasteboard type automatically. Everything else defaults to plain text.

No flags needed for the common case.

Some things you can do with it

Screenshot a window and copy it to clipboard:

screencapture -w -o /tmp/shot.png && cat /tmp/shot.png | pbrich

Convert markdown to a rich text clipboard entry:

echo "**bold** and *italic*" | pandoc -f markdown -t html | pbrich -t public.html

Copy a URL that Finder and browsers recognize as a link:

echo -n "https://github.com" | pbrich -t public.url

Install

brew install waynehoover/tap/pbrich

It’s a single Swift binary with no dependencies. Source on GitHub.