AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

random signature

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
jack



Joined: 04 Sep 2004
Posts: 77
Location: UK

PostPosted: Wed Oct 06, 2004 10:48 am    Post subject: random signature Reply with quote

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
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Wed Oct 06, 2004 12:19 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
jack



Joined: 04 Sep 2004
Posts: 77
Location: UK

PostPosted: Wed Oct 06, 2004 12:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
jack



Joined: 04 Sep 2004
Posts: 77
Location: UK

PostPosted: Wed Oct 06, 2004 12:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
Payam



Joined: 07 Apr 2004
Posts: 58

PostPosted: Fri Oct 08, 2004 10:18 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail MSN Messenger
jack



Joined: 04 Sep 2004
Posts: 77
Location: UK

PostPosted: Fri Oct 08, 2004 11:38 am    Post subject: Reply with quote

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
View user's profile Send private message
savage



Joined: 02 Jul 2004
Posts: 206

PostPosted: Sat Oct 09, 2004 6:02 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group