Three years later, in more civilized times, we have Swift. You can write a short Swift script to pull exactly what you need off of OS X's pasteboard.
Put the following Swift 4 snippet into a new text file. I named mine pbpaste.swift
:
import Cocoa
let type = NSPasteboard.PasteboardType.html
if let string = NSPasteboard.general.string(forType:type) {
print(string)
}
else {
print("Could not find string data of type '\(type)' on the system pasteboard")
exit(1)
}
Then, copy some html, and run swift pbpaste.swift
from the directory where you put that file.
Yay, html! Uggh, OS X added a ton of custom markup (and a <meta>
tag?!) — but hey, at least it's not plain text!
Notes:
NSPasteboard.PasteboardType.html
is a special global that evaluates to the string "public.html"
Obviously this is html specific, so you'd probably want to either:
- Name it
pbpaste-html.swift
, or
- Read the desired type from the command line arguments
It's kind of slow, because it's being interpreted on the fly, not compiled and executed. Compilation gives me a 10x speed-up:
xcrun -sdk macosx swiftc pbpaste.swift -o pbpaste-html
Then just call ./pbpaste-html
instead of swift pbpaste.swift
.