winutils

What is winutils?

winutils is a collection of useful Tcl commands that access some part of the Win32 API. This enables the user to use Windows specific services.

Who wrote it? David Gravereaux


Example :

David Gravereaux mailto:[email protected] recently wrote in news:comp.lang.tcl

 Message-ID: <[email protected]>


 You can simplify that down a whole lot with my winutils extension and its
 winutils::shell command.  It's like `eval exec [auto_execok start] $file &`,
 but without the momentary command prompt flashing up on the screen.

 http://sf.net/projects/tomasoft

 package require winutils
 proc LaunchEditor {myfile} {
    # try the "edit" command first.
    if {[catch {winutils::shell -v edit $myfile}]} {
        winutils::shell -v open $myfile
    }
 }
 proc Launch {args} {
    eval winutils::shell -v open $args
 }

This makes use of associations and even does full URLs in the exact manner and behavior of the "Run..." dialog off the Start menu.

 % Launch mailto:[email protected]?subject=hi%20there&body=was%20up?
 % Launch http://tcl.activestate.com
 % Launch somefile.txt
 % Launch netstat -a 2

I forget if I added the "edit" command to my .tcl association or whether the ActiveTcl installer did it for me..

 % LaunchEditor c:/progra~1/tcl/lib/tcl8.4/init.tcl

Pat Thoyts has suggested the GetLocaleInfo() API [1 ] join winutils.

What other pieces of win32 make a nice fit here?

  • The special folders stuff - SHGetFolderPath() for retrieving the official path to application data user profile etc. This can be important for NT/XP systems where we may have reduced rights to write files elsewhere.

http://sourceforge.net/project/showfiles.php?group_id=1616&release_id=89891

http://prdownloads.sourceforge.net/tomasoft/winutils-0.6.zip


As the "directory watching" ability of winutils appears to undocumented, here is some info straight from David:

  set w [winutils::dirwatch new c:/somedir { puts gotcha! }]

close the watch with:

  winutils::dirwatch delete $w

or if I left the incr Tcl class for it, it would be:

  set w [winutils::dirwatch #auto c:/somedir { puts gotcha! }]
  $w delete

When a file is modified or created in the directory, the script fires. It saves the script as a persistent Tcl_Obj*, so the bytecode rep is maintained. It runs essentially as a proc in that any temp variables are cleared. Use global to link to any globals. I run it also from the scope of the ::winutils namespace, which might not be useful.

I can fire multiple times for the same event. I think because of the flags used with FindFirstChangeNotification(). Some experiments with changing the flags could improve it.