Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

GNU screen has a command, at, which lets you control other sessions by sending screen commands to them. Does tmux have something like that? I tried send-prefix and send-keys, but those send keys to the process running inside tmux; you can't use them to control tmux itself.

Trying to send a control command by doing something like this:

send-keys -t main:1 "tmux select-window -t :1" ENTER

doesn't work if the inner process is something other than a shell. And it also fails if you're sending the keys from a linked session, even when the inner process is a shell. (In that case your current session is the one affected.)

share|improve this question
In general, the way to “script” tmux is to just issue commands through invoking the tmux binary; this works even when the command is run from outside any tmux session (as long as you supply any non-default -L or -S values so it can find the correct server). There should be no need to use send-keys and hope that the receiving pane has an appropriate shell listening. Is there some reason you can not run the tmux select-window -t main:1 directly? Alternateively, bind-key C-n select-window -t main:1 should work as a binding (adjust the key as desired). – Chris Johnsen Feb 22 '12 at 5:38
Ah, yes, that works as I want. I assumed for some reason the select-window command would be done in the context of my current session and link me to that target window, rather than affect the target session separately. I guess I tried everything but the most straightforward option. Thanks. :) Would you mind promoting your comment to an answer, so I can mark it accepted? Then anyone else with the same question will find an accepted answer. – Kurt Hutchinson Feb 22 '12 at 15:02
up vote 2 down vote accepted

Although it is optional, the target window specifier that tmux window commands accept (i.e. for their -t and -s options) can directly specify an window in any session. The syntax for a target window works like this:

  • session:window where
    • session is
      • the specifier for a client (specifies the current session of that client), or
      • an exact, prefix, or fnmatch(3) (i.e. “glob”) match for a session name, and
    • window is
      • a window index, or
      • an exact, prefix, or fnmatch(3) for a window name under session.
  • window (only if there is no colon in the specifier) where
    • window is as above, except that it is restricted to the current session.

The second form is probably the most commonly used form, but it sounds like you want the first form in your case.

You should be able to run this command:

tmux select-window -t main:1

from anywhere to achieve your goal. For example, it will work from a shell script that is executed completely outside the context of a tmux session (e.g. via cron)—as long as you supply any non-default -L or -S tmux option values so that the command can find the server’s socket.

You can also do it as a binding (e.g. in a ~/.tmux.conf file or at a tmux : prompt; adjust the key specifier as desired):

bind-key C-m select-window -t main:1

You could then type your Prefix and C-m in any client attached to any session in any server that has this binding and it will switch the session matching main to its window at index 1.

The “target specifier” syntax is described in the “Commands” section of the tmux manpage (search for the first occurrence of target-client, target-session, target-window, or target-pane to find the relevant descriptions).

I have never used screen’s at command, but it also looks like it has iteration features. There is currently no direct match for that in tmux, but it should be fairly easy to “script” by parsing the output of list-clients, list-sessions, list-windows, and list-panes (newer versions of tmux have the -F option for these commands that can help generate output that it is easier to parse).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.