On the bash terminal, I can issue "Ctrl-Shift-T" to open a new terminal window. How can I do this from a python script which I run on the bash terminal?
1 Answers
Ctrl-Shift-T has absolutly nothing to do with bash but the terminal emulator you are using!
If you want to open a new windows you just use the subprocess module and execute the terminal command (gnome-terminal, xterm etc.)
But in my experience Ctrl-Shift-T opens, not a new window, but a new tab in the current window. That is a bit trickier. But here is a sample how you would do that within a bash-script. This however seems like something that would work on your local machine. But it don't gives me good vibes. Is there another way you could accomplish your task that would be more failsafe on other machines as well? In that case I would recommend it.
I rewrote the bash script i linked to as a Python script. Just make sure you have the tools xprop, xdotool and wmctrl installed.
import subprocess
wid = None
xprop_out = subprocess.check_output(['xprop', '-root'])
for line in xprop_out.splitlines():
if '_NET_ACTIVE_WINDOW(WINDOW)' in line:
wid = line.split()[-1]
if wid:
subprocess.check_call(['xdotool', 'windowfocus', wid])
subprocess.check_call(['xdotool', 'key', 'ctrl+shift+t'])
subprocess.check_call(['wmctrl', '-i', '-a', wid])
else:
print 'Failed to find window ID'

- 1
- 1

- 5,691
- 3
- 30
- 43