Possible keep the text formatting in script that copy selected text + append URL from Chrome/Firefox? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
cadudesun
Posts: 129
Joined: 04 Jun 2016, 10:26

Possible keep the text formatting in script that copy selected text + append URL from Chrome/Firefox?

19 Nov 2018, 08:26

Hi,

I'd appreciate help. The scropt below is what I need, except that the text created in the clipboard (appending browser text selection+URL) isn't formatted anymore. I mean, the formatting from the original text selected in the browser is lost in the script.

Is it possible to keep the text formatting in the script below?

Thanks for help!

Code: Select all

;http://www.donationcoder.com/forum/index.php?topic=26164.0

; Allow partial titlebar text matches.
SetTitleMatchMode, 2
 
; Create a window title group to match on for our hotkey.
GroupAdd, myBrowsers, Mozilla Firefox
GroupAdd, myBrowsers, Google Chrome
 
 
#IfWinActive, ahk_group myBrowsers
{
    F2::
    {
        ; Copy user selection to a variable.
        SendInput, ^c
		Sleep, 100
        myText := Clipboard
        Sleep, 100
        
        ; Switch to address bar in browser and copy URL to another variable.
        SendInput, ^l
        Sleep, 100
        SendInput, ^c
        Sleep, 100
        myURL := Clipboard
        Sleep, 100
    
        ; Format data bits.     
        myData := myText . "`r`n`r`n" . myURL
		Sleep, 100
           
        ; Put formatted data back onto clipboard.
        Clipboard := myData
    }
    Return
} 
#IfWinActive
Rohwedder
Posts: 7643
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Possible keep the text formatting in script that copy selected text + append URL from Chrome/Firefox?  Topic is solved

20 Nov 2018, 03:10

Hallo,
try this (paste with F3):

Code: Select all

;http://www.donationcoder.com/forum/index.php?topic=26164.0
; Allow partial titlebar text matches.
SetTitleMatchMode, 2
;Create a window title group to match on for our hotkey.
GroupAdd, myBrowsers, Mozilla Firefox
GroupAdd, myBrowsers, Google Chrome
#IfWinActive, ahk_group myBrowsers
F2:: ; Copy user selection to a variable.
SendInput, ^c
	Sleep, 100
	myText := ClipboardAll ;formatted data
	Sleep, 100
	; Switch to address bar in browser and copy URL to another variable.
	SendInput, ^l
	Sleep, 100
	SendInput, ^c
	Sleep, 100
	myURL := Clipboard ;unformatted data
Return
#IfWinActive
F3:: ;Paste data
	ClipBoard := myText
	SendInput, ^v ;paste formatted data
	SendInput, `r`n`r`n %myURL% ;send unformatted data
Return
cadudesun
Posts: 129
Joined: 04 Jun 2016, 10:26

Re: Possible keep the text formatting in script that copy selected text + append URL from Chrome/Firefox?

20 Nov 2018, 04:40

Thanks a lot for the script. Exactly what I was looking for!
I just changed the shortcut to !F2 in order I can paste the content in any app without affecting default F keys.
Then:

Code: Select all

!F2:: ;Paste data
	ClipBoard := myText
	SendInput, ^v ;paste formatted data
	SendInput, `r`n`r`n %myURL% ;send unformatted data
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, slowwd, wilkster and 226 guests