[kostix] (01-Nov-2007) created a Tcl/Tk extension to support (a subset of) Windows power management and session management ''events.'' The extension is hosted at http://tkwinpm.googlecode.com and is now at version 0.1 (first public release). The main idea of this extension is to provide a (lighweight) ability for a Tcl/Tk application to "hook" to some Windows power management events (like "the system switched from AC power to the battery", "battery low", etc) and to session management events (like "the user wants to log off", "the system is being shut down", etc). In fact, this extension was written to support graceful disconnects/reconnects to the server(s) on system's suspends/resumes in the [Tkabber] XMPP client (via its unofficial plugin called "green" http://svn.xmpp.ru/repos/tkabber-3rd-party/trunk/plugins/green/). The package is named '''winpm''' and when loaded it registers one command named '''winpm''' in the global namespace. All functionality is available via the subcommands of the '''winpm''' command. Modus operandi of a user of this extension is usually to register callback scripts for certain "Windows events" supported by this extension and then introspect the event which triggered the execution of a script and/or the system's power status. Some examples to get the idea: * Take some action when the system is about to reboot: winpm bind WM_ENDSESSION { lassign [winpm info session] final flags if {[lsearch $flags *LOGOFF] >= 0} { set msg "The user is logging off" } else { set msg "The system is being shut down" } if {$final} { append msg " NOW!" } warn user -with $msg network disconnect workplace save_all quit } * Handle the suspend/resume cycles: winpm bind PBT_APMSUSPEND { warn user -with "suspending..." network save_active_connections network disconnect workplace save_all } winpm bind PBT_APMRESUMEAUTOMATIC { network restore_saved_connections } * Watching the system battery: winpm bind PBT_APMPOWERSTATUSCHANGE { lassign [winpm info power] ac batt capa sec full if {[string equal $ac OFFLINE] && ![string equal $batt UNKNOWN]} { set msg "Battery remaining: $capa%" if {$sec >= 0} { append msg " (estimated $sec seconds to go)" } puts $msg } } The complete documentation is available: http://tkwinpm.googlecode.com/files/winpm.html