Skip to content

Instantly share code, notes, and snippets.

@sgonyea
Forked from dsanson/clipboardRTF2HTML.sh
Created March 16, 2016 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgonyea/687d88dafa20877d138e to your computer and use it in GitHub Desktop.
Save sgonyea/687d88dafa20877d138e to your computer and use it in GitHub Desktop.
#!/bin/sh
# This script converts RTF text on the OS X clipboard to HTML.
osascript -e 'the clipboard as «class RTF »' | \
perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))' | \
textutil -format rtf -convert html -stdin -stdout | \
ruby -ne '@found=true if $_ =~ /<body>/; next unless @found; puts $_; exit if $_ =~ /<\/body>/' | \
grep -v "<body>" | \
grep -v "</body>" | \
pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment