I know how to copy plain text to the clipboard:
oascript -e 'set the clipboard to "plain text"'
But the question is how can I copy html contents to the clipboard?
For example, how can I copy the following html content to the clipboard:
<b>bold text</b>
so that I get bold text when I paste it in TextEdit?
Thanks for the help in advance!
I found an intermediate solution for this:
echo "<b>bold text</b>" | textutil -stdin -stdout -format html -convert rtf | pbcopy
This works, so far so good, but unfortunately I found that it doesn’t work for an image tag:
echo "<img src=\"https://www.google.com/images/srpr/logo3w.png\">" | textutil -stdin -stdout -format html -convert rtf | pbcopy
This does not do the job I want, so anybody knows the reason?
Thanks!
I’ve found a working solution and posted it below 🙂
I’ve found a solution and the idea is to use the HTML class directly instead of the RTF class. (TextEdit or web editors can handle this HTML class as well as the RTF class data)
All you have to do is to convert your html code into raw hexcode.
The complete code looks like:
You can combine them into one sentence, of course.
Hope this helped anybody interested. 🙂