ztcl::device watch
Runs a script at each change of the battery or the network.
ztcl::device watch battery|network -command SCRIPT
Description
Gives a handle, and runs SCRIPT at each change of the battery or of the network, with the dict of ztcl::device battery or network appended as one word. The first change comes soon after the call. The scripts run from the event loop, so a script with no vwait and no Tk never sees them.
While a watch is active, the event loop wakes at least every 20 milliseconds, since the host gives the readings from its own thread. The interpreter stops each watch when it ends.
Returns
A handle, such as device1.
Examples
# A host with no network service, as a desktop.
% catch {ztcl::device watch network -command {puts}} msg; set msg
the network state is not available on this platform
Errors
% ztcl::device watch battery -command {puts}
the battery is not available on this platform
-errorcode ZTCL DEVICE UNAVAILABLE
% ztcl::device watch gps -command {puts}
bad watch "gps": must be battery or network
-errorcode NONE
% ztcl::device watch battery
wrong # args: should be "ztcl::device watch battery|network -command script"
-errorcode TCL WRONGARGS
Facts
- Capability
device. A new interpreter does not have it until the host turns it on.- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.6