Python + Win32: Cut/Paste w/o GUI
Tim Daneliuk
tundra at tundraware.com
Sat Oct 5 15:50:07 EDT 2002
Matt Gerrans wrote:
> At first you said "paste from an arbitrary Windows app" and I was not sure
> what you were trying to do, but if what you really meant was drag-and-drop
> from Explorer to a shortcut, for instance, then there is hope. Try the
> following; if you run it with no parameters, it will create a shortcut to
> itself on the desktop. After that, if you drag-and-drop another icon onto
> that shorcut, it will pop up a message (I know, this is not entirely console
> stuff, but I wanted the results to be clear and anyway, you just wanted to
> get the parameters).
>
> import os,sys,win32com.client,win32ui
>
> if len(sys.argv) == 1:
> shell = win32com.client.Dispatch("WScript.Shell")
> desktop = shell.SpecialFolders("Desktop")
>
> # Might want to get python location from registry, but I'm
> # being lazy.
> python = 'c:\\Python22\\Python.exe'
> target = os.path.join(desktop,'Shorty.lnk')
> link = shell.CreateShortcut( python + ' ' + target )
> link.TargetPath = sys.argv[0]
> try:
> link.Save()
> except:
> print 'Failed to save "%s", maybe it already exists.'%target
> else:
> win32ui.MessageBox( "Quit dropping your %s's on me!" % sys.argv[1] )
>
My apologies for lack of clarity. This isn't quite what I had in mind, but
it is interesting code nonetheless which is going into my "Things That Could
Save Your Life" pile for later use. Many thanks...
--
------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com
More information about the Python-list
mailing list