Prevent Ctrl-Alt-T from opening a new terminal window when one already exist?

3

I would like to know if there is a way to make the Ctrl-Alt-T shortcut behave like it would on xfce. ie: if no terminal is open, open one, else focus on the existing one instead of opening a new one. Ideally without having to install things like xdotool.

I'm using manjaro linux with cinnamon (3.0.7) and gnome-terminal (3.20.2).

K. Rauscher

Posted 2016-10-01T16:15:19.930

Reputation: 33

I know this doesn't technically answer your question, but have a look at Guake, it's a terminal that slides out from the top and can be opened using a custom hotkey (it opens the existing terminal by default)

– cascer1 – 2016-10-13T07:45:16.067

Answers

0

The code in https://stackoverflow.com/questions/1380784/how-to-get-list-opened-windows-in-pygtk-or-gtk-in-ubuntu would tell you if a terminal is open and then you would need to focus the terminal. (Of course, if there is no terminal, open a new one.) Additionally you will need to hook up the Ctrl-Alt-T shortcut to the mini program you create that will control everything.

Edit with working code:

#!/usr/bin/python

import gi
gi.require_version('Wnck', '3.0')
from gi.repository import GdkX11, Gdk, Wnck
import subprocess   

screen = Wnck.Screen.get_default()
screen.force_update()  # recommended per Wnck documentation

# loop all windows
for window in screen.get_windows():
    window_name = window.get_name()
    print window_name
    if window_name == "your_terminal_name_here":
        now = GdkX11.x11_get_server_time(Gdk.get_default_root_window())
        window.activate(now)
        break
    continue
else:
    subprocess.call("gnome-terminal")

    # clean up Wnck (saves resources, check documentation)
window = None
screen = None
Wnck.shutdown()

Put this code in a file called check_window.py and link a shortcut to it in Preferences> Keyboard> Shortcuts. Make the file executable with chmod +x check_window.py Replace if window_name == "your_terminal_name_here": with the name of your terminal. If you run this 'app' one time with your terminal window open it will give you the name of your windows.

theGtknerd

Posted 2016-10-01T16:15:19.930

Reputation: 142