| View previous topic :: View next topic |
| Author |
Message |
caveatrob
Joined: 28 Oct 2006 Posts: 188
|
Posted: Sun May 13, 2007 12:04 am Post subject: Prefix clipboard lines with quote >> character for ema |
|
|
Hi all,
I'm trying to figure out how to make a script that prepends each line of the clipboard with a quote marker ">>" for email.
I'm trying to turn off the automatic quoting feature in gmail so I can selectively copy and paste that which I want to quote and indicate that the material was quoted.
Thanks!
Rob |
|
| Back to top |
|
 |
*MsgBox Guest
|
Posted: Sun May 13, 2007 12:34 am Post subject: |
|
|
This does it.
| Code: | Loop parse, clipboard, `n
{
l:=A_LoopField
a = %a%>>%l%`n
}
StringTrimRight a, a, 1
clipboard := a
MsgBox % a |
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sun May 13, 2007 3:18 pm Post subject: |
|
|
| Code: | StringReplace c, ClipBoard, `n, `n>>%A_Space% , All
ClipBoard := ">> " . (SubStr(c,-2)=">> " ? SubStr(c,1,StrLen(c)-4) : c) | With RegExReplace you can do it in one line, but it is somewhat slower. [Bugfixed]
Last edited by Laszlo on Mon May 14, 2007 12:01 am; edited 1 time in total |
|
| Back to top |
|
 |
Lazslo Guest
|
Posted: Sun May 13, 2007 6:43 pm Post subject: |
|
|
Laszlo, I see that yours is the nicer solution, but why the SubStr and StrLen functions? As far as I can see, this works just as well:
| Code: | StringReplace c, ClipBoard, `n, `n>>%A_Space%, All
ClipBoard = >>%A_Space%%c% |
Also I have just noticed that using caveatrob's post as the text, your code leaves out his name. ....I'm confused! |
|
| Back to top |
|
 |
*MsgBox Guest
|
Posted: Sun May 13, 2007 6:44 pm Post subject: |
|
|
| Sorry, that was me. |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sun May 13, 2007 10:04 pm Post subject: |
|
|
| *MsgBox alias Lazslo wrote: | | why the SubStr and StrLen functions? | They just remove the trailing ">> " in a new line. If you don't mind having this extra three characters in the last line, drop the last expression out, as you did.
The script did not leave out anything, when I tried it in my XP SP2 laptop. Could you make sure, the name was properly selected? |
|
| Back to top |
|
 |
MsgBox
Joined: 17 Nov 2005 Posts: 181 Location: Leicester, UK
|
Posted: Sun May 13, 2007 10:55 pm Post subject: |
|
|
Your code replaces `n with `n>>%A_Space%. There isn't a `n after the word Rob, therefore no trailing >>.
I tested both again (just to be sure), mine worked and yours didn't. :p
but...
if there is a new line selected AFTER the word Rob, then my version has a trailing >> and your version works.  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sun May 13, 2007 11:51 pm Post subject: |
|
|
I see. Try this: | Code: | StringReplace c, ClipBoard, `n, `n>>%A_Space% , All
ClipBoard := ">> " . (SubStr(c,-2)=">> " ? SubStr(c,1,StrLen(c)-4) : c) |
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4710 Location: Boulder, CO
|
Posted: Sun May 13, 2007 11:59 pm Post subject: |
|
|
...and here is the single line version: | Code: | | ClipBoard := ">> " . RegExReplace(ClipBoard,"`n([^$])","`n>> $1") |
|
|
| Back to top |
|
 |
polyethene
Joined: 11 Aug 2004 Posts: 5248 Location: UK
|
Posted: Mon May 14, 2007 4:44 pm Post subject: |
|
|
...which could be simplified to:
| Code: | | clipboard := RegExReplace(clipboard, "m)^", ">> ") |
_________________ GitHub • Scripts • IronAHK • Contact by email not private message. |
|
| Back to top |
|
 |
|