proc text'watch'file {w file {mtime -}} { set checkinterval 1000 ;# modify as needed if {$mtime eq "-"} { if [info exists ::_twf] {after cancel $::_twf} set file [file join [pwd] $file] text'watch'file $w $file [file mtime $file] } else { set newtime [file mtime $file] if {$newtime != $mtime} { set answer [tk_messageBox -type yesno -message \ "The file\n$file\nhas changed on disk. Reload it?"] if {$answer eq "yes"} {text'read'file $w $file} text'watch'file $w $file } else {set ::_twf [after $checkinterval [info level 0]]} } } proc text'read'file {w file} { set f [open $file] $w delete 1.0 end $w insert end [read $f] close $f } #-- Testing: pack [text .t -wrap word] -fill both -expand 1 set file textwatch.tcl text'read'file .t $file text'watch'file .t $fileif 0 {The dialog should come up when you change the file externally, say by touch-ing it in pure Tcl, which might be done with
file mtime $filename [clock seconds]or editing it with another editor.
See also [1] for watching directory-changes in a similar way....