send(n)

πŸ’Œ send(n) β€” the Tk built-in that lets you whisper commands into another app's ear πŸ’…

Hiii bestie, welcome to the Tk Built-In Commands manual, page send(n). Grab a strawberry matcha, we're learning remote execution today and it's lowkey iconic. πŸ“βœ¨


✨ NAME ✨

send β€” execute a command in a different application. Yes, a different application. It's giving long-distance relationship but make it Tcl. πŸ¦‹


🌸 SYNOPSIS 🌸

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

πŸ’– DESCRIPTION πŸ’–

So here's the tea: send arranges for cmd (and its args) to get executed inside the application named by app. Then it hands you back the result or error from that execution, like a little messenger pigeon that also does receipts. πŸ•ŠοΈ

app can be the name of any application whose main window is sitting on the display that contains the sender's main window. And no, it does not need to be in the same process. Different process? Different vibe? Doesn't matter. 🫢

Now, the command itself:

  • If there are no arg arguments, then the whole command to be executed lives entirely inside the cmd argument.
  • If there's one or more args, they get concatenated together to form the command to be executed β€” literally just like the eval command does it. Same energy. πŸ’«

And if the initial arguments of the command start with -, they're treated as options. Here's what's currently defined, bestie:

  • -async β€” requests an asynchronous invocation. In this case send completes immediately without waiting for cmd to finish in the target application. No result will be available, and any errors in the sent command get straight-up ignored. πŸ™ˆ And if the target application happens to be in the same process as the sending application, then -async is just... ignored entirely. Sorry girl. πŸ’€
  • -displayof pathName β€” says 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, "hey, look over there." πŸ‘€
  • -- β€” serves no purpose except to terminate the list of options. You only need this one if app could contain a leading - character. That's it. That's the whole job. πŸŽ€

🌈 APPLICATION NAMES 🌈

An application's name is set initially from the name of the program or script that created the application. You can query it and change it with the tk appname command. Cute, right? ⭐


🚫 DISABLING SENDS 🚫

If send gets removed from an application (like, say, with the command rename send {}), then that application will not respond to incoming send requests anymore, and it won't be able to issue outgoing requests either. Fully off the grid. 🧚

Good news though: communication can be reenabled by invoking the tk appname command. Glow-up era. πŸ’œ


πŸ”’ SECURITY πŸ”’

Okay bestie, this is the serious part and I need you to actually read it. 😭

The send command is potentially a serious security loophole. Not a vibe. Here's why:

On Unix, any application that can connect to your X server can send scripts to your applications. Those incoming scripts can use Tcl to read and write your files and invoke subprocesses under your name. Like, under your name. Ma'am. πŸ’€

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 it's 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.

This means applications cannot connect to your server unless they use some other form of authorization, such as that provided by xauth. πŸ”

Under Windows, send is currently disabled. Most of the functionality is provided by the dde command instead. πŸͺŸ


πŸ‘‘ EXAMPLE πŸ‘‘

This script fragment can be used to make an application that only runs once on a particular display. Main character energy, honestly:

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 page, bestie!! This one's from the Tk 4.0 era, page send(n), and honestly? It ate. Now go forth and send responsibly β€” and maybe double-check your xauth situation first. πŸ’…βœ¨ πŸŽ€

πŸ“¦ where this page comes from
  • fedora 43: tk 1:9.0.2-2.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
  • fedora 43: tk 1:9.0.2-2.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
  • fedora 44: tk 1:9.0.2-2.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
  • fedora 44: tk 1:9.0.2-2.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms