0

Let's say I want to bind a key sequence in GNU screen to jump to a specific window. I might do so like this:

bind ^t exec screen -X select foo

(I've deliberately simplified this; the real-world application execs a command which dynamically figures out which window to switch to, then runs the screen -X command.)

Great; this works well. The problem comes when I've attached (via screen -x) to the same session from a different machine. On the new machine, ^a^t does as expected and switches to the window. But, if I return to the original machine, leaving the new machine attached, then ^a^t switches to the window on the new machine. If I detach the new machine, everything goes back to working as normal.

Note that this is one session, so -S is of no use. The session is not password-protected. It also doesn't seem to relate to the exec machinery: while manually running screen -X select foo inside screen on the original machine works properly, running it in a separate terminal on the original machine (i.e. outside screen) still switches the window on the other machine.

How can I force screen -X to affect only the attached user on the same machine it's being run from? (Affecting both users/machines would also be acceptable, if that's easier.)

2
  • How are you connecting to the session on original machine from new machine? Commented Mar 30, 2022 at 21:27
  • I'm just doing ssh $orig_machine and then, once logged in, screen -A -x $screen_name. Commented Apr 1, 2022 at 7:01

1 Answer 1

0

I think the at command should be a solution to what you are seeing. In the description for the at command in screen's man it says:

at [identifier][#|*|%] command [args ... ].
...
In shared windows the command will be repeated for each attached display.
...

Which sounds like it should switch the window in both places.

1
  • 1
    Yes! this works. To be more clear, screen -X at "$USER*" select foo will do it for both displays. To affect only one or the other, you have to work out what TTYs each one are running screen on. Once you do that, you can do, say, screen -X at pts/1% select foo etc. Commented Apr 26, 2022 at 1:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .