Append to av2 the two lines of script:
tkwait visibility .rc.fff
send av {sendNow}
Append to av the script:
proc sendNow {} {
global b
send av2 [list setCfg $b]
}
The Tk command tkwait suspends further processing until certain condition is satisfied. This is primarily used to make popup dialog boxes modal. This is useful for instance to make certain actions are carried out before proceeding further (e.g. A file is selected from a popup fileselectionbox before Tcl/Tk attempts to open the file).
Here av2 is made to wait until the base frame appears on the screen before a send request to "av' is sent.
Note: Try without this and see what happens. Try also placing the last line send av {sendNow} before the definition of the procedure "setCFG".
send is synchronous. The sending application will suspend processing its user events until the execution of the sent script in the remote application is completed and send returns the result. However the sending application can respond to send events from other applications while it awaits its own send.
Procedure sendNow creates a list of two elements made up of the string "setCfg" and the value of "b". It then passes this list as a script to a Tk application in the same display/screen as itself whose name is "av2" to be executed within av2.