Version 7 of send

Updated 2002-03-29 14:29:46

send - Execute a command in a different application http://www.purl.org/tcl/home/man/tcl8.4/TkCmd/send.htm

 send ?options? app cmd ?arg arg ...?  

This command arranges for cmd (and args) to be executed in the application named by app. It returns the result or error from that command execution. App may be the name of any application whose main window is on the display containing the sender's main window; it need not be within the same process. If no arg arguments are present, then the command to be executed is contained entirely within the cmd argument. If one or more args are present, they are concatenated to form the command to be executed, just as for the eval command.

If the initial arguments of the command begin with "-" they are treated as options. The following options are currently defined:

-async Requests asynchronous invocation. In this case the send command will complete immediately without waiting for cmd to complete in the target application; no result will be available and errors in the sent command will be ignored. If the target application is in the same process as the sending application then the -async option is ignored.

-displayof pathName Specifies that the target application's main window is on the display of the window given by pathName, instead of the display containing the application's main window.

-- Serves no purpose except to terminate the list of options. This option is needed only if app could contain a leading "-" character. (From: Tk help)


Send is a revelation. Many Tk (and even Tcl) programmers claim it as indispensable. Start by reading the distribution documentation [L1 ].


Can different Tk bindings communicate through send? Yes--Perl/Tk, Tcl/Tk, and Tkinter are all happy sending messages to each other with built-in send. At some point, we need to present examples of this ... Steve Lidie devotes an entire chapter of his Perl/Tk book to send.


Start small with your send programming. Use a couple of simple Tk instances, to work out the security and application-name issues. Once those are properly settled, it's usually quick work to automate as much as you choose.


CAVEAT: The Tk send command depends on working with an X server and thus does not work normally on Windows or MacOS. Check out dde for Windows and Tcl's AppleScript support for Mac.


See also comm (a send look alike based on sockets which should work cross platform and cross machine), dde, and other methods listed in the Inventory of IPC methods.


Pat Thoyts gave this example for a send substitute with DDE in the Tcl chatroom:

 # Emulate the 'send' command using the dde package if available. 
 if {[info command send] == {}} { 
    if {![catch {package require dde}]} { 
        dde servername TkInspect-[pid] 
        proc send {app args} { 
            eval dde eval [list $app] $args 
        } 
    } 
 } 

PT writes on 29 March 2002:

I have released a preliminary version of a send for MS Windows systems that uses COM to do the work of registering interpreters and passing messages around. See http://tclsoap.sourceforge.net/winsend.html for more information and for the package (binary at the moment until I tidy the code :) )


Tk syntax help - Arts and crafts of Tcl-Tk programming - Category Command, part of the Tk package