How can I send html to the clipboard as rich text from a script? My end goal is create a script so I can paste content from a source file into an email, but I want a general answer for pasting into any program that accepts rich text.
Example usage for pasting into email:
- Open the source file in vim
- Use
:TOhtml
command to create an html file with vim's syntax highlighting - Use an answer from here to copy the html as rich text
- Paste into an email (this one wouldn't be scripted)
Related: Pasting diff output into Microsoft Outlook with syntax highlighting
Best Answer
Linux
via this answer
Mac
via this answer
Windows
In older Windows, you can natively only copy plaintext (via this answer).
In PowerShell you can copy rich text:
If you create a C:\sandbox\pbcopy.ps1:
Then you can enable scripts and then run it from anywhere (cmd.exe, .bat files, etc):
There are a few different Cygwin commands to copy to Windows clipboard and it looks like cygwin provides xclip, so you could probably use the Linux solution on Windows if you have cygwin.