Paste RTF text to OneNote while retaining formatting
Posted: 13 Jun 2017, 22:48
When you copy code from IDE's such as Eclipse the format of copied text is RTF. This is not supported by OneNote. So, only plain text is copied without formatting.
But, Microsoft Word supports RTF. If you copy the code to RTF the formatting is retained and the text is converted to HTML format. Now if you copy this text from Word back to OneNote, the formatting is retained because now it's HTML and not RTF.
So, I wrote this little script that does this.
I'm new to AHK. So, there might be better solutions to this. But so far I'm satisfied with the outcome. I just posted in case someone else might find it useful.
But, Microsoft Word supports RTF. If you copy the code to RTF the formatting is retained and the text is converted to HTML format. Now if you copy this text from Word back to OneNote, the formatting is retained because now it's HTML and not RTF.
So, I wrote this little script that does this.
I'm new to AHK. So, there might be better solutions to this. But so far I'm satisfied with the outcome. I just posted in case someone else might find it useful.
Code: Select all
;copy RTF text from IDE and convert to HTML using Word
convert_rtf_to_html(){
send, ^c ;copy text from IDE
openWord() ;open new word doc or go to currently opened word doc
sleep, 300
send, ^v ;paste text to word
sleep, 300
send, ^a ;select all text
sleep, 200
send, ^x ;cut all text
sleep, 200
winactivate ahk_exe onenote.exe ;go to oneNote window
return
}
;open new word doc or go to currently opened word doc
openWord(){
IfWinExist ahk_exe winword.exe ;if word is open go to word window
winactivate ahk_exe winword.exe
else{ ;;if word is not open, word program
run, "<<address of word>>\winword.exe"
sleep, 400 ;; wait for intro menu to load
Send,{Enter} ;; to get blank page
}
return
}