Using the script below to toggle visibility (with a key combination), you can have one terminal window (completely) hidden when minimized, as if it wouldn't exist, while another terminal window keeps visible in the launcher when minimized.
Create a separate profile for the hidden terminal window
The trick is to create a separate profile in the gnome-terminal
preferences, with a distinctive name in the window title. This makes it possible to identify the terminal window with the wmctrl -l
command and unmap it with xdotool
's windowunmap command, making it invisible in the Launcher.
Toggle visibility / open a "hidable" window with a key combination
You will have to set up a key combination to toggle visability of the terminal window, since it is not visible in the launcher (see further below).
How to setup
The script needs both xdotool
and wmctrl
to be installed:
sudo apt-get install xdotool
sudo apt-get install wmctrl
Then:
Create a separate profile in gnome-terminal
preferences: choose "Edit" > "Profiles", click "New".
- Name the new profile (exactly) "Hidden"
In the "Title & Command" tab, set the window title to (exactly) "Hidden_Profile", to be placed before window title:
N.B. You might have to log out / in for the profile to be "loadable"
Test if the profile works by running the command:
gnome-terminal --window-with-profile=Hidden
a window should pop up, with "Hidden_profile" in the window title:
Copy the script below into an empty file, save it as run_hidden.py
Test run it by the command:
python3 /path/to/run_hidden.py
What it should do:
- Run it if no terminal window from the separate profile is running: a new terminal should open from the separate ("hidable") profile.
- Run it a second time: the window will be (completely) hidden, also from the launcher
- Run it a third time: the window should re-appear
If all works fine, add the (command to run-) the script to a shortcut combination: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:
python3 /path/to/run_hidden.py
The script
#!/usr/bin/env python3
import subprocess
import os
home = os.environ["HOME"]
hidden_windowid = home+"/.window_id.txt"
get = lambda cmd: subprocess.check_output(cmd).decode("utf-8")
def execute(cmd):
subprocess.check_call(cmd)
try:
w_id = [l.split()[0] for l in get(["wmctrl", "-l"]).splitlines() if "Hidden_Profile" in l][0]
execute(["xdotool", "windowunmap", w_id])
with open(hidden_windowid, "wt") as out:
out.write(w_id)
except IndexError:
try:
with open(hidden_windowid) as read:
w_id = read.read()
execute(["xdotool", "windowmap", w_id])
except subprocess.CalledProcessError:
execute(["gnome-terminal", "--window-with-profile=Hidden"])
Explanation
The script uses wmctrl
to identify the window by its (window-) name, as we gave it in the separately created profile for this purpose. Once we have the id
, we can unmap it with xdotool
's windowunmap
command.
To make sure we can make the window reappear, the id
is stored in a hidden file; if re-mapping fails, the script concludes there is no window opened from the special profile, and it opens one by the command:
gnome-terminal --window-with-profile=Hidden