Move operation to clipboard

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Ruy ElPequenoCid
Posts: 7
Joined: 12 Jun 2018, 19:51

Move operation to clipboard

27 Feb 2019, 14:59

Hello,

I am at my wits ends with this one and I could use a hand.

Scenario

I copy one paragraph or many paragraphs (from anywhere) and using this script I can parse the clipboard and send it, line by line, nested within the appropriate <p></p> tags. I am posting a working script, albeit not the solution I need.

A sample pair of lines/paragraphs:

Code: Select all

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris. 
The script:

Code: Select all

^!+p::

	loop, parse, clipboard, `n, `r
		{
			SendRaw, <p>%A_LoopField%</p>`r
		}
	
return
The outcome:

Code: Select all

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.</p>
The problems
  • SendRaw struggles in cases where the text is large, the lag is visible
  • Deadkeys followed by vowels render incorrectly (this is expected behavior as I use a Spanish keyboard layout - not to be taken as the focus of this question)
I would like to have the script perform the operation in the clipboard, and then I could simply add a CTRL+V instruction at the end.

Unfortunately I cannot get it to work. Can someone help me? Thanks! :geek:
User avatar
sinkfaze
Posts: 613
Joined: 01 Oct 2013, 08:01

Re: Move operation to clipboard

27 Feb 2019, 15:28

Code: Select all

^!+p::
var :=	Clipboard
Loop, parse, var, `n, `r
{
	Clipboard :=		"<p>" A_LoopField "</p>`r"
	ClipWait
	SendRaw, ^v
}
return
:?:
User avatar
Ruy ElPequenoCid
Posts: 7
Joined: 12 Jun 2018, 19:51

Re: Move operation to clipboard

27 Feb 2019, 16:05

sinkfaze, thanks so much for helping me.
  • I regret that your solution does not work 100% of the time.
  • When copying multiple paragraphs from some sites the script only processes the first paragraph, ignoring all the others.
  • Other times, having copied lines from a Notepad which contain some special characters, it just outputs a pair of <p></p> tags just empty like that.
Anyways, thanks for helping! :thumbup:
User avatar
sinkfaze
Posts: 613
Joined: 01 Oct 2013, 08:01

Re: Move operation to clipboard

27 Feb 2019, 16:23

Can you post samples of text where the code fails? Redact any sensitive information if necessary.
User avatar
Ruy ElPequenoCid
Posts: 7
Joined: 12 Jun 2018, 19:51

Re: Move operation to clipboard

15 Mar 2019, 11:03

Sorry for the delay, for whatever reason the forum would not let me post this reply for many days. It would just throw a blank page, I've tried so many times. Let's hope this one goes.

Ok, I made a small video/screen capture demonstrating both behaviors (your solution first, followed by the original I made).

Code: Select all

dropbox.com/s/y51xwqi9s8bow6n/demo_autohotkey_01.mp4?dl=0
Kobaltauge
Posts: 174
Joined: 09 Mar 2019, 01:52
GitHub: MassimoCastell
Location: Germany
Contact:

Re: Move operation to clipboard

17 Mar 2019, 07:48

Hi

The clipboard is overwritten every cycle. Therefore, you get only the last paragraph.
And at the end you SendRaw ^c. This doesn't paste the clipboard, it sends literally "^c"

This worked in my tests.

Code: Select all

^!+p::
Loop, parse, Clipboard, `n, `r
{
	if (A_LoopField <> "")
	{
		tmpvar := "<p>" A_LoopField "</p>`r"
		cmplvar := cmplvar . tmpvar
	}
}
Clipboard := cmplvar
ClipWait
Send ^v

return
list
Posts: 145
Joined: 26 Mar 2014, 14:03
Contact:

Re: Move operation to clipboard

18 Mar 2019, 15:55

Depending on what other tasks you have in mind Lintalist may be something for you, https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3378

This snippet would take care of your request and you can assign it to a hotkey or hotstring:

Code: Select all

[[clipboard=Wrap|<p>|</p>]]

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], teadrinker and 237 guests