Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

trigger script on file change in WinME

by Anonymous Monk
on Jul 29, 2001 at 11:27 UTC ( [id://100654]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm on Windows ME, and i know this is kind of a long shot, but is there a way to have a perl script triggered every time i edit a text file WITHOUT running a timer or something every xx hours, minutes, seconds, etc, that checks if the file's been changed?

Edit kudra, 2001-07-30 Changed title per ntc

Replies are listed 'Best First'.
DirMon.pl and Win32::ChangeNotify, was Re: I know this probably isn't possible, but...
by Albannach (Monsignor) on Jul 29, 2001 at 17:47 UTC
    I think your best bet is to look at Win32::ChangeNotify, and the excellent example (which is likely to be close to what you are after) in Dave Roth's DirMon.pl. Unfortunately I can't say whether this will work under WinME, but it is certainly worth a look, as is all of Dave's work.

    --
    I'd like to be able to assign to an luser

Re: I know this probably isn't possible, but...
by tachyon (Chancellor) on Jul 29, 2001 at 15:47 UTC

    Well it's not impossible and even though it is not really Perl here is how to do it. Presuming by 'edit' you mean double click on the file to open it in an editor.

    First you need to understand that under Windows each file extension is associated with a program. When you double click on a icon Windows looks at the file extension associated with that icon and uses the program associated with that extension to open the widget denoted by the icon. In this way clicking on a txt file opens the file in a text editor but clicking on a graphic file opens a graphics viewer.

    The file associations are set automatically in general but you can set them in Windows explorer. For example files that end in .txt are associated with notepad.exe (the actual executable that generates the notepad editor). When you click on a .txt file windows fires up notepad.exe and passes the name of the file you double clicked to it. The effect is the same as doing this on the command line:

    c:\>notepad.exe somefile.txt

    Knowing this the task is easy. First we write this batch file.

    rem this silences this batch file if the rem is removed rem echo off rem this executes the perl script perl c:\myscript.pl rem this will execute notepad with the double clicked prog c:\windows\notepad.exe %1

    Type this into any text editor like notepad and save it as 'widget.bat' You can use any name you like but you need the .bat to let Windows know this is a batch file that can be executed. The %1 gets us the name of the file that was double clicked in Windows. Now all you do is change the file association of the .txt files from 'notpad.exe' to 'widget.bat'. Open Windows explorer then View|Options|File Types. This should get you a long list of file types and their associations. Edit the .txt file association to point at your batch file and you are done. Note on some versions of windows the menu location an name is different from above. The menu option is somtimes called Folder Options - you should find it easily. Now when you double click on a text file widget.bat will execute which first executes your perl script and then executes notepad.exe which opens the double clicked text file.

    Although this does what you (I think) you said you wanted it is better to run a daemon in the background that monitors writes to files and filters the writes to .txt files as I can edit a text file using any number of methods other than by double clicking on them. This however is very non perl so we might leave this here. It is a simple task so maybe post on a more Windows specific site.

    The impossible yesterday, miracles take a little longer...

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: I know this probably isn't possible, but...
by synapse0 (Pilgrim) on Jul 29, 2001 at 11:31 UTC
    Well.. i've never tried it, but I would imagine it might be possible to kludge the application type (windows explorer -> tools -> folder options ..) for your editor and have it try and run the script, then open the editor..
    No clue if it'll work, but it's worth looking into..
    -Syn0
Re: I know this probably isn't possible, but...
by Masem (Monsignor) on Jul 29, 2001 at 15:32 UTC
    If I'm extrapolating your situation correctly, you basically want to edit locally a file stored elsewhere? If so, remember that with any Win OS after 95rev2 you have the ability to set up "web folders" that act as file explorer windows to FTP sites. This may or may not be what you want, but it's a possible solution that's easy to use.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Re: I know this probably isn't possible, but...
by aquacade (Scribe) on Jul 29, 2001 at 21:16 UTC
    Check out: http://www.spectre.com/spectretech/PolterGeist.html It seems to be one of the few schedulers for Windows. I'm not sure (looking at their site) if ME is supported. Did you consider the (yuk) Windows Task Scheduler? Not very friendly, but might give you some help right away.
Re: I know this probably isn't possible, but...
by Anonymous Monk on Jul 29, 2001 at 22:39 UTC
    ok, thanks for the help, but i guess i'll just run a script in scheduled tasks to back the text file up if it's been changed (and it'll run every 15 min). my problem now is, when the scheduler runs the script, that big ugly dos window will pop up in the middle of my screen. what i want to do now, is to hide the console window so that it wont surprise me at an inopportune time...i know this is possible, but i don't know how to do it...

      If you're running ActiveState, it comes with an alternate executable wperl.exe that is a true Win32 app. and so doesn't display the console window. This is great for applications like yours, as well as writing Tk or Win32::GUI apps in Perl. :-) I usually set up an association with wperl.exe for any files with the extension .plw.

      If you're not using ActiveState, or don't have a wperl.exe for some reason, you can make your own or you can try the work-around.

      bbfu
      Seasons don't fear The Reaper.
      Nor do the wind, the sun, and the rain.
      We can be like they are.

        how does being a win32 app change what perl can do? can i still use file tests like -e and -M? and can i still use localtime?
      From 'My Computer' find the script that the scheduler is going to run. Right click -> Properties and look at the bottom of the 'Program' tab. The 'Run' drop list has an entry for 'Minimized' and below that there's a 'Close On Exit' check box. It's probably different under ME, but that's how it looks under 98.

      /\/\averick

Re: I know this probably isn't possible, but...
by Chady (Priest) on Jul 29, 2001 at 15:03 UTC

    Try editing the file from within perl; make a script to edit the file with, using a form text field maybe with PWS, and then this script will trigger the other, or have it built in.

    Update: Windows ME doesn't support PWS, there's no NT Option Pack for ME...


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://100654]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-24 02:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found