Although it is optional, the target window specifier that tmux window commands accept (i.e. for their
-s options) can directly specify an window in any session. The syntax for a target window works like this:
- 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
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-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-panes (newer versions of tmux have the
-F option for these commands that can help generate output that it is easier to parse).