Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 437
MehdiB Avatar asked Oct 21 '25 06:10

MehdiB


1 Answers

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.

like image 183
Thomas Maier Avatar answered Oct 23 '25 22:10

Thomas Maier