How to use xdotool to open a new tab, switch to it and run commands in it

gnome-terminal open new tab and run command
xdotool examples
xdotool linux
xdotool python
bash script open new terminal tab and run command
bash script to open new terminal and run command
gnome execute command
gnome-terminal execute command stay open

I am trying to write a bash script to automate running some commands. However some of these commands should be running in their own terminal tab. So I use the following in my bash script to open a new tab:

xdotool key ctrl+shift+t

this does the job, but the next commands in my bash script are still executed in the previous terminal tab. How can I make the new opened terminal tab active and run the next commands in this tab?

What Terminal Emulator are you using? It strongly depends on this.

In general, you could write the commands you want to execute in a shell script and tell your terminal emulator to execute the script once it has started.

Example with xterm:

echo '#!/bin/bash' > /tmp/thescript 
echo 'ls -la' >> /tmp/thescript
chmod +x /tmp/thescript
xterm -hold -e /tmp/thescript

EDIT: I just saw that u asked for a way to achieve this with xdotool. So this answer might be invalid. Please tell me if so - then i'll delete it.

Programmatically open tab in gnome-terminal, execute command , Gnome-terminal can either execute a command or open a shell, but not both. gnome-terminal | head -1)" xdotool windowfocus $window xdotool key ctrl+shift+t xdotool type "$*" xdotool key Return. I use it like this: $ run-in-new-tab 'ls -l'. However some of these commands should be running in their own terminal tab. So I use the following in my bash script to open a new tab: xdotool key ctrl+shift+t

If all you want is to run the commands in the background / in parallel, without synchronously waiting for each command to complete before the next begins, terminate them with an ampersand & to instruct the shell to do so.

Alternatively, you can execute the commands in their own subshells by surrounding each with parentheses ( ). If they are long running processes or you do not wish to pollute the original shell with their output, you can fork them off and capture their output to file with something like (setsid command 1>/path/to/log &).

If separate tabs is necessary requirement, you can use xdotool to key the switch-to-the-next-tab binding or similar, and then key the commands you must run in that tab.

Instead of sorting out that mess yourself, you could use a script from this answer by Jacob Vlijm, which wraps a windowed approach that uses xdotool and wmctrl to 'send' commands to different terminal windows. The script is written in python 3 but it can easily be rewritten for a shell environment of choice.

A more direct approach involves use of a TIOCSTI ioctl to inject characters into another terminal. According to the tty_ioctl manual page:

       ioctl_tty - ioctls for terminals and serial lines



       The  ioctl(2) call for terminals and serial ports accepts many possible
       command arguments.  


   Faking input

       TIOCSTI   const char *argp
              Insert the given byte in the input queue


Here are c and perl wrappers, and an example in python as referenced by this answer.

open gnome terminal with several tabs and execute a few , Please note, as soon as the processes executed by -e are done running, they will terminate. See Open a new tab in gnome-terminal using command line. Open History in a new tab (web UI) Ctrl + J. Open Downloads in a new tab (web UI) Ctrl + L. Select the URL in the address bar to edit. Ctrl + M. Mute current tab (toggle) Ctrl + N. Open a new window. Ctrl + O. Open a file from your computer in Edge. Ctrl + P. Print the current page. Ctrl + R. Reload the current page. Ctrl + S. Save the current

How are you using xdotool? It can be done with a chain, for example:

$ xdotool key "ctrl+shift+t"; xdotool type "ls"; xdotool key Return

Command to open new tab in the current terminal, If you just want to open a new tab. To open a new tab in the current opened terminal you can press SHIFT + CTRL + T . Alternatively, use the� Run a command: Windows + P: Project a screen: Alt + Tab: Switch to previous window: Alt + Space: Restore, move, size, minimize, maximize or close current window. Also works like a charm for

Open a new tab in gnome-terminal using command line, gnome-terminal open new tab and run command, When you start GNOME take a while to start new shell :( xdotool type --delay 1 --clearmodifiers "$@" xdotool For anyone seeking a solution that does not use the command line: ctrl+shift+t. Open Focused Link in New Background Tab Ctrl + Enter command + return (see note, below) Open Focused Link in New Foreground Tab Ctrl + Shift + Enter command + shift + return Note: The Foreground and Background Tab shortcuts are switched if the setting When you open a link in a new tab, switch to it immediately is enabled in Options Preferences

xdotool - command-line X11 automation tool, It does this using X11's XTEST extension and other Xlib functions. Aliases exist for "alt", "ctrl", "shift", "super", and "meta" which all map to Foo_L, or until a new xdotool command is seen, because no xdotool commands are valid keystrokes. The command run as a result of the behavior is run with %1 being the window � Press Alt+Tab to open the switcher and keep holding down the Alt key. Rather than pressing Tab, use the arrow keys on your keyboard to highlight the window you want, and then release the Alt key, press the Enter key, or press the space bar. Use Your Mouse to Switch and Close Windows. You can also use your mouse with the Alt+Tab switcher.

Ubuntu – Is there a command in Gnome-Terminal, or any tabbable , Ubuntu – Is there a command in Gnome-Terminal, or any tabbable shell to open a new tab New window; New Tab; Close Current tab or window; Maximise Shell echo "alias nt='xdotool getactivewindow $(xdotool key ctrl+shift+t)'" >> . bashrc We can use wmctrl here: wmctrl -r :ACTIVE: -b toggle,maximized_vert,� My scripts reside in ~/scripts. uses xdotool to do a control + Tab every 10 seconds. Change to meet your needs. This moves the kiosk from one tab to the next. #!bin/bash xdotool search --onlyvisible --class Chromium windowfocus watch -n 10 xdotool key ctrl+Tab ***this went from tab to tab every 10 seconds.