Command to open new terminal window from the current terminal?
Matthew Martinez
I installed xdotool by running sudo apt-get install xdotool and throw xdotool key ctrl+alt+t command to open a new terminal window from the current one.But it was not working.
What was the command to open a new terminal window from the current gnome-terminal?
13 Answers
Just this command will do:
gnome-terminalNormally if you want a command to open from the terminal and separate (so it returns to the prompt without having to close the opened program), you have to use something like this:
gnome-terminal & disownHowever the parent terminal seems to detect that the same command is being used so you don't need to do that and gnome-terminal will suffice. This also seems to happen when running xfce4-terminal from Xfce's terminal, konsole from KDE's as well (doesn't seem to work when running xterm from xterm (see also xterm xterm) - Running konsole from Gnome/Unity & Xfce's terminal works as well, but for Xfce's terminal in gnome terminal you need xfce4-terminal & disown).
For more visit gnome-terminal's manual page:
gnome-terminal [-e, --command=STRING] [-x, --execute ] [--window-with-profile=PROFILENAME] [--tab-with-profile=PRO‐ FILENAME] [--window-with-profile-internal-id=PROFILEID] [--tab-with-profile-internal-id=PROFILEID] [--role=ROLE] [--show-menubar] [--hide-menubar] [--geometry=GEOMETRY] [--disable-factory] [-t, --title=TITLE] [--working-direc‐ tory=DIRNAME] [--usage] [-?, --help] 9 Command to open new terminal window from the current terminal,
xdotool key ctrl+shift+nTo install xdotool,
sudo apt-get install xdotool 6 The following script will open a new tab in the current gnome-terminal window and optionally give that tab a title. This works from any window, you don't have to be in a gnome-terminal window to run it. And, if there is no gnome-terminal running, it will start one. The only caveat is that if you changed the hotkey for opening a new tab you might have to change the line xdotool key ctrl+T to use your hotkey instead.
#!/bin/bash
DELAY=1
# get title we are going to set tab too, default to Terminal
title="Terminal"
if [ $# -eq 1 ]; then title="$1"
fi
# get pid of running terminal server
TPID=$(ps -C gnome-terminal-server -o pid | tail -1 | sed -e's/\s//g')
if [ ${TPID} == "PID" ]; then # no terminal process running yet, so just start one gnome-terminal -t "$title" --tab exit 0
fi
# there is a terminal, get window id of the running terminal server
WID=$(wmctrl -lp | awk -v pid=$TPID '$3==pid{print $1;exit;}')
# get title of currently active tab
TTITLE=`xwininfo -id 0x5000006 | grep xwininfo | awk '{print $5;exit}'`
if [ "$TTITLE" == "\"Terminal\"" ]; then # so we don't go into an infinite loop later TTITLE="we had a terminal named terminal $$"
fi
# get focus on active terminal tab
xdotool windowfocus $WID
# use keyboard shortcut to open new tab
xdotool key ctrl+T
# see if we have created tab and are in terminal
NTITLE=`xwininfo -id 0x5000006 | grep xwininfo | awk '{print $5;exit}'`
waited=0
while [ "$TTITLE" == "$NTITLE" ]; do # sleep for 1 second before we try again xdotool sleep 1 NTITLE=`xwininfo -id 0x5000006 | grep xwininfo | awk '{print $5;exit}'` if [ $waited == 0 ]; then echo "Waiting " waited=1 fi echo -n "."
done
if [ $waited == 1 ]; then echo ""
fi
# active tab is the new one we created, wait DELAY seconds just to be sure we can type into it to set tab name
xdotool sleep $DELAY
xdotool type --clearmodifiers "termtitle $title"
xdotool key Return
# make tab the active window and raise it to top
wmctrl -i -a $WID
exit 0