3

I am using Ubuntu 14.04 and I am trying to remove a running program from the launcher.

Specifically I want to launch two terminals. One is for my normal work with several tabs, the other one is needed for a running ssh connection. I want to hide the second one from the launcher and "minimize it to tray" (that's how I would call it in Windows).

Is there a way to do this?

5
  • 1
    You can use different workspaces, but in Unity, I think the icons will stay in the launcher anyway. In LXDE, you have by default 2 entirely independent workspaces. But you also have no launcher...
    – Byte Commander
    Mar 10, 2015 at 14:20
  • @ByteCommander: I won't be able to change to a different UI in the office anyway. Just moving it to a different workspace isn't actually that bad. The second terminal won't pop up, if I click the icon in the launcher while on a different workspace. I guess I could live with that. Thanks. :)
    – Core_F
    Mar 10, 2015 at 14:25
  • Feroc, could you mention if you tried the answer(s), if it is what you are looking for or not, if you ran into problems etc. Mar 13, 2015 at 15:35
  • @JacobVlijm: I actually just used ByteCommanders solution. That already worked fine with me, no need for a more fancy way.
    – Core_F
    Mar 17, 2015 at 14:26
  • The nice thing you could have done is to ask @ByteCommander to post it as an answer and accept it, and to mention it is the solution for you. It would have prevented the three people below to take the time to answer the question. I know I wouldn't have if I knew you would have a satisfying solution. Mar 17, 2015 at 14:37

4 Answers 4

4

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:

  1. 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:

      enter image description here

      N.B. You might have to log out / in for the profile to be "loadable"

  2. 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:

    enter image description here

  3. Copy the script below into an empty file, save it as run_hidden.py

  4. 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
  5. 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
2
  • Wow, impressive work! Upvoted. That is leagues above my two-workspaces hint...
    – Byte Commander
    Mar 17, 2015 at 14:43
  • @ByteCommander Thank you so much, but your solution turned out to be the practical solution to OP :) Mar 17, 2015 at 14:45
3

To give you the ability to accept the solution you chose as an answer, I repeat my comment from above. Although it is just a simple workaround and can not really concurrent with @JacobVlijm's impressive answer!

So my hint to you was to just enable the use of different workspaces in your system settings panel. When you have a window opened in one workspace, it is not visible in the others.

But with Unity, the icon in the Launcher gets highlighted anyway, even if the only open window is in another workspace.
In other DEs (I know XFCE and LXDE), this is not the case. The panel/taskbar does not show running programs of inactive workspaces there.

1

I used Tilda for this in the past. It has nice feature of showing up and hiding like it's namesake did in Doom or Quake. If you prefer Python version, it's there as well, name's Guake.

It's basically another terminal app, that binds itself to a key combo, and shows only when you press said key combo (hides of course on it as well).

sudo apt-get install guake - for Tilda see it's page.

Now, obviously you may not want another terminal app, for some one is just enough. Some though, prefer more than one, because:

  • it's different app for a different purpose
  • it's cool when it slides down, it's cool it stays hidden when not needed
  • they liked Quake
2
  • That sounds nice, I will give it a try tomorrow.
    – Core_F
    Mar 10, 2015 at 18:34
  • Or Yakuake on KDE. And both Terminator and XFCE Terminal can be made to do this.
    – muru
    Mar 10, 2015 at 18:42
0

There's a built-in option to do that, but it's a little bugged:

  1. Open the first Terminal (the one that you want to be visible) using Ctrl+Alt+t
  2. Open the second Terminal (the one that you want to be hidden) using Ctrl+Alt+t.
  3. Make the second Terminal the active window, then hit Ctrl+Alt+s and click elsewhere.

To retore the hidden Terminal, click on the Terminal icon in the launcher.

The problem with this method is that sometimes, due to a bug, you'll need to close all the visible Terminals first in order for the hidden Terminal to show up again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .