Using PythonWin32 to copy text to Windoze Clipboard for Unix-style random .sig rotator?

D

dananrg

Can you tell I miss Unix?

I want to write a Python script that, when launched, will choose a
random .sig (from a list of about 30 cool ones I've devised), and store
the .sig text in the Windows Clipboard, so I can then paste it into any
Windows application.

This way, it'll work for Outlook e-mails, Yahoo, Gmail, etc.

Also, could I use Python to programmatically set key combos to do
certain things?

Should I buy the Python on Win32 book? Are all my answers there? Or is
there a good PyWin32 FAQ where all (that I'm interested in with this
particular e-mail) will be revealed?

Spammity-spam, y'all.

Thanks.

Dana
 
F

Fredrik Lundh

Can you tell I miss Unix?

by your early-nineties spelling of Windows ?
I want to write a Python script that, when launched, will choose a
random .sig (from a list of about 30 cool ones I've devised), and store
the .sig text in the Windows Clipboard, so I can then paste it into any
Windows application.

since most Python distributions comes with Tkinter, you can use Tkinter's
clipboard interface. unfortunately (at least for this use case), Tkinter re-
moves things it has added to the clipboard when the program terminates,
so you have to make sure that the program is still running when you need
the text.

here's a fortune generator that keeps posting important stuff to the clip-
board at random intervals:

import Tkinter
import random, time

# get some phrases
import StringIO, sys
stdout = sys.stdout
try:
sys.stdout = StringIO.StringIO()
import this
FORTUNES = sys.stdout.getvalue().split("\n")[2:]
finally:
sys.stdout = stdout

# create an invisible (well, not really) window
root = Tkinter.Tk()
root.withdraw()

def refresh():
fortune = random.choice(FORTUNES)
root.clipboard_clear()
root.clipboard_append(fortune)
root.after(random.randint(100, 1000), refresh)

refresh()

root.mainloop()

(since this will make it impossible to use the clipboard for anything else, you
might wish to use a button instead of a timer to update the clipboard...)

</F>
 

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top