send(3tk)

πŸ’Œ send(3tk) β€” or, how to yell across apps πŸ’Œ

okay bestie, welcome to the glow-up guide for send, a Tk built-in command. yes it's giving ✨remote execution✨, yes it's giving πŸ’€security nightmare if you're carelessπŸ’€, and yes we're gonna get into all of it. buckle up. πŸŽ€


🌸 NAME 🌸

send β€” execute a command in a different application. literally just vibe-transferring your commands to another app's house. 🏠✨


πŸ¦‹ SYNOPSIS πŸ¦‹

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

πŸ’– DESCRIPTION πŸ’–

so here's the tea: this command arranges for cmd (and args, if you brought friends) to be executed in the application named by app. it hands you back the result or the error from that execution, like a little messenger pigeon that actually comes home. πŸ•ŠοΈ

app can be the name of any application whose main window is on the display containing the sender's main window. note it does not need to be in the same process β€” we're crossing process boundaries here, no cap. 🌈

now, the arguments:

  • if no arg arguments are present, then the whole command to be executed lives entirely inside the cmd argument. one and done.
  • if one or more args are present, they get concatenated to form the command to be executed, just as for the eval command. same energy fr fr.

and if the initial arguments of the command start with -? those get treated as options, bestie. here's what's currently defined πŸ‘‡


✨ OPTIONS ✨

  • -async β€” requests asynchronous invocation. meaning: send completes immediately without waiting for cmd to finish in the target application. no result will be available, and errors in the sent command will be ignored. πŸ™ˆ oh, and if the target application is in the same process as the sending application, then -async is just… ignored. it's giving "sure jan." πŸ’…
  • -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. basically: "not that screen, THIS screen." πŸ–₯️➑️πŸ–₯️
  • -- β€” serves no purpose except to terminate the list of options. it's the "ok we're done with options now" flag. you only need it if app could contain a leading - character. king of doing the bare minimum, honestly. πŸ‘‘

πŸ‘‘ APPLICATION NAMES πŸ‘‘

the name of an application is set initially from the name of the program or script that created the application. you can query and change the name of an application with the tk appname command. that's it, that's the section. short and iconic. πŸŽ€


🚫 DISABLING SENDS 🚫

if the send command is removed from an application (e.g. with the command rename send {}) then that application will not respond to incoming send requests anymore, nor will it be able to issue outgoing requests. it's giving ghosting, but on purpose. πŸ‘»

good news tho: communication can be reenabled by invoking the tk appname command. the friendship is repairable. 🫢


πŸ”₯ SECURITY πŸ”₯

okay bestie, this is the part where we get serious. 🚨

the send command is potentially a serious security loophole. do not sleep on this.

on Unix, any application that can connect to your X server can send scripts to your applications. and those incoming scripts can use Tcl to read and write your files and invoke subprocesses under your name. that's not a vibe, that's a whole identity theft situation. 😭

host-based access control such as that provided by xhost is particularly insecure β€” because it allows anyone with an account on particular hosts to connect to your server, and if disabled it allows anyone anywhere to connect to your server. πŸ’€

in order to provide at least a small amount of security, Tk checks the access control being used by the server and rejects incoming sends unless:

  1. xhost-style access control is enabled (i.e. only certain hosts can establish connections), and
  2. the list of enabled hosts is empty.

what this means: applications cannot connect to your server unless they use some other form of authorization, such as that provided by xauth. ✨

and under Windows? send is currently disabled. most of the functionality is provided by the dde command instead. different app, different channel. πŸ“±


😭 LIMITATIONS 😭

under macOS/aqua, the send command works only with interpreters that exist in the same process (these are returned by "winfo interps"). invocations that target an interpreter that exists in another process don't accomplish anything. it's giving "I texted but the message never delivered." πŸ•³οΈπŸ“¨


🌟 EXAMPLE 🌟

this script fragment can be used to make an application that only runs once on a particular display. obsessed. 😌

if {[tk appname FoobarApp] ne "FoobarApp"} {
    send -async FoobarApp RemoteStart $argv
    exit
}
# The command that will be called remotely, which raises
# the application main window and opens the requested files
proc RemoteStart args {
    raise .
    foreach filename $args {
        OpenFile $filename
    }
}

πŸ”‘ KEYWORDS πŸ”‘

application, dde, name, remote execution, security, send


and that's the whole send(3tk) manual page, bestie!! πŸ’– this one shipped with Tk 4.0, and the page itself is dated the same β€” so yeah, she's an elder but she still eats. πŸ“ tysm for reading, go forth and send responsibly, and pls pls pls don't leave your X server wide open. iykyk. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from