lixpas lixpas - 1 year ago 103
Bash Question

How to bypass window shell (wish/tclsh) GUI and use terminal instead?

I have a software package that has a very cumbersome GUI written in tclsh/wish. I would like to control the software via terminal and make some scripts to run it. The wish GUI is quite long (over 37000 lines) so I would like to avoid reading it in detail and writing a respective command-line interface. Suppose I already know the sequence of buttons which I want to press and entry-fields to fill. Is there a way I can control this wish GUI monster via terminal?

The GUI is called via:

exec wish -f $PROGRAM_PATH/program.tcl -n program wish $PROGRAM_PATH $*

Even if I remove the -f flag it wouldn't take any terminal input or display the % prompt. I don't understand the part following the -n flag. The programs runs the same if I remove it.

i.e. calling simply

wish $PROGRAM_PATH/program.tcl

does the same thing.

I tried the -file flag as well and supply external file with commands, but wish tried to input these commands before all the internal variables and routines were defines, so it resulted in an unrecognized command.

Can anybody point me to some useful source about wish scripting?

Answer Source

If you had a program prog.tcl, which has an entry field .e, and a button .b:


package require Tk

set e {}

proc dump { } {
  global e
  puts $e

ttk::label .l -text Entry:
ttk::entry .e -textvariable e
grid .l .e
ttk::button .b -text button -command dump
grid .b -column 2

You can use a script like this to run it:


package require Tk

source prog.tcl

set tv [.e cget -textvariable]
set $tv mydata
.b invoke

This only works if you have the source, which it appears you do.

Instead of generating events to enter data in the entry field, it is much easier to just get the associated variable and set it to the required value. Buttons are easy. There are also comboboxes (drop-downs), checkboxes, scales and radio buttons to work with. I use these methods extensively for my automated testing and it works.

You will still have to read the code to find out the entry and button names.

If you are on Windows, you could also try the autohotkey program.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download