____ _ _ _ _ | _ \(_)_ __ ___ | |_ _____ _| |_ __ _ _ __ __| | | |_) | | '_ \ / _ \ | __/ _ \ \/ / __| / _` | '_ \ / _` | | __/| | |_) | __/ | || __/> <| |_ | (_| | | | | (_| | |_| |_| .__/ \___| \__\___/_/\_\\__| \__,_|_| |_|\__,_| _ |_| | | _____ _ _ _ __ _ __ ___ ___ ___ ___ ___ | |/ / _ \ | | |_____| '_ \| '__/ _ \/ __/ __|/ _ \/ __| | < __/ |_| |_____| |_) | | | __/\__ \__ \ __/\__ \ |_|\_\___|\__, | | .__/|_| \___||___/___/\___||___/ |___/ |_| _ _ _ _ __ _(_) |_| |__ | |_ _ __ ___ _ ___ __ \ \ /\ / / | __| '_ \ | __| '_ ` _ \| | | \ \/ / \ V V /| | |_| | | | | |_| | | | | | |_| |> < \_/\_/ |_|\__|_| |_| \__|_| |_| |_|\__,_/_/\_\ [Pipe text and key-presses with tmux] by TheOuterLinux (https://theouterlinux.gitlab.io) Last updated: 2023/05/13 Tmux is a terminal multiplexer; meaning, you can have one terminal window but split it into multiple terminals. However, it does have one very interesting feature: "send-keys." Using the "send-keys" argument, you can... drum-roll... send keyboard presses to a tmux session; you no longer have to run an 'xmacro' program, which do not work in TTY, to do things automatically in command-line programs that have their own shell. Maybe this will make more sense with an example. Let's say that one day you felt like playing around with FluidSynth but wanted to use the shell except have a bunch of things done automatically for you. When the 'fluidsynth' program is ran by itself, you get a shell like so: FluidSynth runtime version 2.2.3 Copyright (C) 2000-2021 Peter Hanappe and others. Distributed under the LGPL license. SoundFont(R) is a registered trademark of Creative Technology Ltd. Type 'help' for help topics. > If we wanted a "one-liner" to use 'tmux' to open 'fluidsynth' and then have it also run "help" within fluidsynth's shell, do something like so: tmux new-session -s TITLEOFSESSION fluidsynth \; send-keys "help" Enter ...The above opens a tmux session, gives it the name "TITLEOFSESSION," runs 'fluidsynth,' and then sends the text "help," followed by an Enter key-press. However, let's say you wanted more key-presses... tmux new-session -s TITLEOFSESSION fluidsynth \; send-keys "help" Enter \; send-keys "help player" Enter \; HOWEVER, you can also send key-presses from another terminal using: tmux send-keys "help" Enter ...assuming that you only have one tmux session running. Another program out there is called 'expect,' but it is only good for running against BASH scripts that use the 'read' command. Also the multitude of suggestions to use 'echo' and "> /dev/pts/#" together may pipe text to another terminal, but "\n" only does a new-line, not an actual Enter/Return key-press when it comes to another program's shell.