[Tutor] Invoking python script
alan.gauld at btinternet.com
Sun Feb 17 16:57:39 CET 2013
On 17/02/13 09:14, Brajesh pant wrote:
> Hello there ..
> I want to know is there any python module which can tell
> when a cut command or copy command is invoked.
There are but probably not trivially. but you need to understand what
you are asking for. A cut/copy command is a desktop environment thing
that is specific to the GUI and the application you are using. It would
include any cut/copy action including manipulating text in a word
processor or numbers in a spreadsheet. These are commands to an
application to do something to its underlying data model. In the case of
a File explorer that model is the file system, in a web browser its the
screen artifacts being displayed (actually the DOM).
So just because you detected cut/paste commands in the GUI that would
not necessarily be the commands you are interested in, and there ay be
other ways of modifying the files (eg via command line) that cut/copy
would not detect.
In fact if you used a different file explorer (eg a KDE v a Gnome based
one) you probably wouldn't detect those events. Unless you are doing
something atbthe GUI level that is almost certainly the wrong starting
> Actually i want to build a utility such that a when a file or folder
> is copied i want to automatically run my python script ..
And this is a far different thing because you specifically want to
monitor the file-system regardless of how the files get moved.
This is very dependent on the OS and even the file-system. For example
with a journalling file-system it will be much easier to do this than
with the old DOS FAT based system or even older Unix systems like ext2.
And I don;t know of any Python modules that would help directly, I
suspect you need to get down 'n dirty with the OS itself.
I'll be interested to see what other folks suggest on this one.
Author of the Learn to Program web site
More information about the Tutor