Ubuntu – Always hide an application’s window

firefoxubuntu-tweakunityworkspaces

I'm using the selenium webdriver to run automated tests in firefox on my web applications, and while it's all working perfectly, it's a little bit annoying how firefox pops up over everything while it's running.

Is there a way I can always always always by default hide firefox? Or minimize it every single time it opens or something?

What I'd really like is for it to always open in a default workspace. I'm using Ubuntu Tweak so I have 16 x 16 workspaces. Can I get firefox to always open in a certain one?

Best Answer

The following script lets you select a window , and will keep that window minimized while the script is running. It supports only one windows, so if you open new window of application - that window won't be affected.

You can run it easily like so:

python keep_minimized.py

When the script starts, mouse cursor will turn into a cross. Select the window you want to keep minimized. Now every time that window gains focus (be it via launcher click or Atl+Tab), it will be minimized.

You can obtain the script from here or from github gist

from gi.repository import GdkX11,Gdk
import subprocess
import time

def run_sh(cmd):
    # run shell commands
    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    out = p.stdout.read().strip()
    return out 

def get_window_xid():
    for item in run_sh("xwininfo -int").split("\n"):
        if "Window id" in item:
           return item.split()[3]

user_selection = get_window_xid()
screen =  Gdk.Screen.get_default()
while True :
    time.sleep(0.25)
    active_window = screen.get_active_window()
    if int(active_window.get_xid()) == int(user_selection):
        active_window.iconify()
Related Question