Using pbcopy & pbpaste with rich text formatting results in empty clipboard
I've found plenty of resources that say this should work, but I'm having no luck with rich text formatting with the pcopy
& pbpaste
commands on MacOS Catalina 10.15.4.
% echo '**foo**' | pandoc -t rtf -s | pbcopy -pboard general -Prefer rtf
% pbpaste -pboard general -Prefer rtf
<nothing>%
Pasting with ⌘V doesn't work either, is empty.
Formatting information is definitely being stored somewhere though, when I copy formatted text in a google document and re-paste it somewhere else the formatting is conserved, but no matter what I do with pbpaste
it results in plain text output.
Solution 1:
In my experience it's impossible to get RTF data out of pbpaste
, even if the man page says otherwise.
I suggest you use pbv for that.
For example, after copying the following rich text string into your clipboard:
"Hi, I'm rich text"
pbv
is able to give you back proper RTF data:
$ pbv public.rtf | textutil -stdin -info
File: stdin
Type: rich text format (RTF)
Length: 19 characters
Contents: "Hi, I'm rich text"
Whereas pbpaste
will always output plain text even when instructed to prefer RTF:
$ pbpaste -Prefer rtf | textutil -stdin -info
File: stdin
Type: plain text
Length: 19 characters
Contents: "Hi, I'm rich text"
Found via this similar question.