Adding up all the numbers in the clipboard
Wouldn’t it be nifty to have a hotkey that will add up all the numbers in the clipboard? You could select a table on a webpage and instantly add up the values. Or if you wanted to add up a bunch of numbers, just type out the numbers, copy them to the clipboard, then hit the hotkey.
Scripting/automation tools make this pretty easy to do. Here’s such a script for AutoHotKey for Windows:
Typing sum [Tab] will output the sum of any numbers found in the clipboard.
Scripting/automation tools make this pretty easy to do. Here’s such a script for AutoHotKey for Windows:
::sum::
Sum := 0
String := Clipboard
FoundPosition := 1
Loop
{
FoundPosition := RegExMatch(String, "[0-9.]+", Match, FoundPosition)
If FoundPosition = 0
{
Break
}
Sum := Sum + Match
FoundPosition := FoundPosition + StrLen(Match)
}
Send %Sum%
return
Typing sum [Tab] will output the sum of any numbers found in the clipboard.
2 Comments:
Hi Jon,
I found this on the web, and I think it is exactly what I need as I frequently need to do a quick sum of cells returned from SQL Server while debugging code.
However I cannot get this to work in AutoHotKey at all. I can't seem to get your script to run against an assigned key. Any suggestions as to what I'm doing wrong?
Thanks in advance,
Richard
By Richard Rose, at 7/29/2011 1:16 a.m.
Hi Richard,
Alas, I now use a Mac, so I don't readily have a copy of AutoHotKey to try this again on.
Jon
By Jonathan, at 7/29/2011 5:33 p.m.
Post a Comment
<< Home