Winclip.SetRTF doesn't work

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
reverberation
Posts: 314
Joined: 13 Dec 2015, 20:48

Winclip.SetRTF doesn't work

20 May 2018, 11:39

As per the code below, it works perfectly when in MS Office. However, it doesn't work when I try it on forums/website textboxes.

I read around and heard advice that I should change it to either SetText or SetHTML. Unfortunately, both did not work as well. Nothing appears.

Can anyone advise what is the issue?

Code: Select all

::copy1:: 
WinClip.Clear()
Drives := "CD"
Loop Parse, Drives
    if FileExist(A_LoopField ":\Dropbox\AHK\1RTFs") {
rtf := FileOpen(A_LoopField ":\Dropbox\AHK\1RTFs\Copy.rtf", "r").read()   
}
WinClip.SetRTF(rtf)
WinClip.Paste()
Return
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Winclip.SetRTF doesn't work

20 May 2018, 11:57

- The clipboard uses clipboard formats that can be viewed using NirSoft InsideClipboard.
- These include RTF and html, and other text/image/other formats.
- MS Office can probably handle RTF, but perhaps your web browser can't.
- If you feed the contents of an RTF file into SetText or SetHTML, it should treat the contents as though it were plaintext/html.

- You'll probably have to convert your RTF text into html. Three ideas:
- Use software to convert the rtf files to htm files.
- Put rtf onto the clipboard, paste into a program, copy from that program, now rtf *and* html will be on the clipboard.
- Convert rtf to html from within AutoHotkey, I'm not sure how this can be done.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
reverberation
Posts: 314
Joined: 13 Dec 2015, 20:48

Re: Winclip.SetRTF doesn't work

25 May 2018, 06:26

why would it not work if I simply use SetHTML? any other straightforward method i can try?
Guest

Re: Winclip.SetRTF doesn't work

25 May 2018, 07:59

Why do you expect it work? You SET it to one format, the clipboard does not automagically convert between formats. So depending on your target program you need to use RTF or HTML. Chances are that HTML will also work where RTF works so in general you would be better off using HTML and not RTF as HTML would be more flexible (it would work in Word, Wordpad, Write, Open Office, Web Browser, Nearly all Email programs etc)

So convert RTF to HTML and use SetHTML and problems are solved

If you can't switch the RTF 2 HTML because the source has to be RTF (or comes from source that generates RTF) use a command line convertor (there are many here is one specific https://sourceforge.net/projects/rtf2html/ or you can use http://pandoc.org/ (bigger program) to convert RTF to HTML file (you will hardly notice the delay I'm sure) and use SetRTF for RTF and SetHTML for HTML - you can set various formats - incl plain text if you wish (just use a regex on the HTML file to get the plain text version, this works for me:

Code: Select all

WinClip.SetHTML(RTF-FILE)
WinClip.SetHTML(HTML-FILE)
Text:=RegExReplace(html,"iU)</*[^>]*>") ; strip HTML tags so we can paste normal text if need be
WinClip.SetText(Text)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada and 306 guests