Python + Win32: Cut/Paste w/o GUI

Andy Robinson andy at reportlab.com
Sat Oct 5 04:21:23 EDT 2002


>Disclaimer:  I'm *much* more comfortable with Unix innards than Win32, so if
>the question I am about to ask is stoopid, please bear with me...
>
>
>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.

You need a "helper app" which can respond to events - most probably a
GUI. I have done similar things in Delphi in the past, inspired by
NextStep which had a wonderful "services" features like this.  (In
NextStep you could write scripts to do something to a chunk of text,
'register' them on a special menu, and have them available in any app
to manipulate the current text selection).

Tha app could accept a command line argument which is the default
Python script to run, so you can make many desktop links to it. I
suggest that when invoked it grabs text off the clipboard, manipulates
and pastes it back.

To genuinely drag and drop text, you probably need a running app,
either in a little window or in the system tray - not just a desktop
icon.  

This sounds like a neat little excuse for a generic utility of
interest to all Python users - wish I had more time these days :-)

- Andy Robinson




More information about the Python-list mailing list