Paste plain text- Use AutoHotKey to strip RTF/HTML formatting

Paste plain text

I (like everyone else in the world) frequently copy-paste between various programs. While some programs like Word and Excel allow for paste plain text, a lot do not.

Paste plain text

I wrote a small script in AutoHotKey which takes the contents of the clipboard and strips it of HTML/RTF format. This way it allows me to paste as plain text in any program by hitting a key combination (Control+G). ¬†What’s great is that I don’t actually lose the original format so, if I decide I actually wanted the original content, I can still just paste with Control+V and I’m good to go!

Below is the actual code for doing the above in AutoHotKey.

 
^g:: ;Control G =Paste Text version of Clipboard
Store:=ClipboardAll  ;Store full version of Clipboard
  clipboard = ; Empty the clipboard
  SendInput, ^c ;copy highlighted text ;SendInput to Send if you have issues
  ClipWait, 1
    If ErrorLevel ;Added errorLevel checking
      {
        MsgBox, No text was sent to clipboard
        Return
      }
SendInput, ^v ;paste plain text ;you might switch SendInput to Send if you have issues
Sleep, 50
Clipboard:=Store ;restore clipboard to original content
Return

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.