| View previous topic :: View next topic |
| Author |
Message |
jack
Joined: 04 Sep 2004 Posts: 77 Location: UK
|
Posted: Wed Oct 06, 2004 10:48 am Post subject: random signature |
|
|
i have a file of signature lines. this key definition picks a line at random from the file and sends it to whereever i'm typing.
like this:
jack
Four bananas make a bunch and so do many more
| Code: | #S::
count = 1
;read lines from file into an array
loop read, D:\aut\MAIL-HEADERS.TXT
{
line%a_index% = %A_LoopReadLine%
count++ ; increment counter, so we know how many lines there are
}
random choice, 1, %count% ; pick a line at random
stringtrimleft result, line%choice%,0 ; extract chosen line from the array
send jack{RETURN}
send %result% |
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Oct 06, 2004 12:19 pm Post subject: |
|
|
Nice, I was wondering how you manifest all those delightfully cryptic sig lines.
One tiny thing: since count is initialized to 1 rather than 0, your count at the end will wind up being one larger than the actual number of sig lines. This will probably cause a blank sig line to appear once in a while. |
|
| Back to top |
|
 |
jack
Joined: 04 Sep 2004 Posts: 77 Location: UK
|
Posted: Wed Oct 06, 2004 12:31 pm Post subject: |
|
|
| Quote: | | One tiny thing: since count is initialized to 1 rather than 0, your count at the end will wind up being one larger than the actual number of sig lines. This will probably cause a blank sig line to appear once in |
ah. it hasn't happened yet so i never spotted that bug. mind you, i've only been using it for a couple of weeks. i used to do the random selection using Python, put the result on the clipboard, then use autohotkey to paste in the clipboard contents :)
thanks
jack
But there are also unknown unknowns |
|
| Back to top |
|
 |
jack
Joined: 04 Sep 2004 Posts: 77 Location: UK
|
Posted: Wed Oct 06, 2004 12:36 pm Post subject: |
|
|
not that anybody cares, but here is the Python i was using to do the same thing:
import random
import win32clipboard
sigfile = open('D:\\aut\\MAIL-HEADERS.TXT','r')
alllines = sigfile.readlines()
sigfile.close()
selection = random.choice(alllines).strip()
win32clipboard.OpenClipboard(0)
win32clipboard.SetClipboardText(selection)
win32clipboard.CloseClipboard()
jack
an intellectual carrot...the mind boggles |
|
| Back to top |
|
 |
Payam
Joined: 07 Apr 2004 Posts: 58
|
Posted: Fri Oct 08, 2004 10:18 am Post subject: |
|
|
Jack, off topic but I've heard a lot about how powerful Python is though I have no exprience with it.
AHK has just been incredible -- I'm wondering if/when you might have a use for Python instead of AHK...any benefits? any time when you have to use Python instead?
Thanks
Payam |
|
| Back to top |
|
 |
jack
Joined: 04 Sep 2004 Posts: 77 Location: UK
|
Posted: Fri Oct 08, 2004 11:38 am Post subject: |
|
|
if you have to do a lot of text processing, python is much more powerful and very simple. it's very good at string formatting, lists, dictionaries.
it is good when you you need stuff that autohotkey can't do. for example:
i recently wrote a python program that sends SMTP mail messages with random content to random mail addresses, with random recipients, with random sent dates and random attachments. it sounds rather strange, but it was (and is) very useful for some software testing.
some time ago i wrote a program that does database access, getting results to match a user's query.
i don't suppose that helps much. anybody else use python?
jack
they have taken their eyes off the ball and are not seeing the wider issues |
|
| Back to top |
|
 |
savage
Joined: 02 Jul 2004 Posts: 206
|
Posted: Sat Oct 09, 2004 6:02 am Post subject: |
|
|
| I dabbled in perl for a while, then I dabbled in python. I'm still playing, but I find it to be very enjoyable to use. It's simple and powerful. I'll probably end up using it a lot. |
|
| Back to top |
|
 |
|