OSX app to paste and save HTML content?

Solution 1:

Although this is an old question, it's still relevant, and here is the answer:

pbpaste -Prefer rtf | textutil -stdin -convert html -output outputfile.html

This uses the built-in OS X pbpaste utility to pipe the contents of the clipboard to stdout (-Prefer rtf is probably unnecessary but doesn't hurt), then runs it through the built-in textutil program. The -stdin argument makes textutil take its input from pbpaste; -convert html tells it to turn the input into HTML; and -output outputfile.html tells it to write the output to a file called outputfile.html.

If you find that the output has some unnecessary elements, you can exclude them with -excludedelements; for example, -excludedelements '(span, font, head, xml)'. Note that you need to have the single quotes because your shell will try to interpret the parentheses as a special shell expression.