Python + Win32: Cut/Paste w/o GUI

jay graves jgraves3 at austin.rr.com
Sat Oct 5 05:51:31 CEST 2002


On 04 Oct 2002 20:50:08 GMT, Tim Daneliuk <tundra at tundraware.com>
wrote:

>I want to be able to do the following but am unclear if/how it can be done:
>1) Write a non-GUI Python script.
>2) Create a shortcut in Win32 to that script.
>3) Copy text from an arbitrary Win32 application.
>4) Paste the copied text to the aforementioned shortcut/python script and
>    have that pasted text be somehow available (argv[] ???) for use by that
>    script.
>Can this be done?
>------------------------------------------------------------------------------
>Tim Daneliuk
>tundra at tundraware.com

If I understand you correctly, I think it can be done with some extra
programs.

I have a text file on my desktop (at work and I'm at home now, so I
can't post the code) with extension of 'clipdata'.  I registered a new
file type in windows with this extension and I created two actions.
The default action, runs my python script and the other action edits
the file.  The python program uses a popen call to the 'gclip.exe'
from the unxutils package (http://unxutils.sourceforge.net/) which
writes the clipboard data to stdout.  I read from the popoen call and
I have whatever was in the clipboard.  I then write this to the top of
the 'clipdata' file with a time stamp.  I use this a temporary holding
place for little scraps of code or SQL.  All I have to do is load up
the clipboard and then dbl-click the icon on the desktop  (I have a
command line function also) and the data is saved for posterity.
The unxutils package also has a 'pclip.exe' which sends stdin to the
clipboard, which I also have used with sucess.

Hopefully this helps.  If need be I can send you the code on Monday.
Just email me.

...
jay







More information about the Python-list mailing list