The preferred option
If an application offers the option to start up in tray, no doubt that is the preferred option.
If not however, you either need to edit the application's code and recompile (not the most obvious option), or you need to "repair" the behaviour of the startup procedure. A slightly edited version of this script can do the job in that case.
About this answer
I am deliberately ignoring the line in your question:
"not closing these applications to the system tray"
Since closing the window after it came into existence, leaving the icon in tray, simply is the only option we have. Effectively you won't notice the difference however.
The script starts up the application, running the command you gave as first argument.
Then the script checks the window list (with the help of
wmctrl) for windows, with the pid of the application you started.
If the window appears, it is immediately closed gracefully, with the help of the
wmctrl -ic <window_id>
without a transmission (in this example) window at all. Obviously the image is from Unity, but it works the same on
To prevent an endless loop if the window might not appear for some reason, the script practices a time limit of 30 seconds for the window to appear.
No need to mention that the script will only startup the application in system tray if the application has a system tray icon, else it will simply close the application completely if ist only window is closed.
command = sys.argv
command_check = command.split("/")[-1]
subprocess.Popen(["/bin/bash", "-c", command])
t = 1
while t < 30:
w_list = [l.split() for l in subprocess.check_output(["wmctrl", "-lp"]).decode("utf-8").splitlines()]
proc = subprocess.check_output(["pgrep", "-f", command_check]).decode("utf-8").strip().split()
match = sum([[l for l in w_list if p in l] for p in proc], )
subprocess.Popen(["wmctrl", "-ic", match])
except (IndexError, subprocess.CalledProcessError):
t += 1
How to use
The script needs
sudo apt-get install wmctrl
Copy the script into an empty file, save it as
Test- run the script with the application as argument, e.g in the
python3 /path/to/run_intray.py transmission-gtk
If all works fine, you can add it to Startup Application, but note that you most likely will have to add a small break before the command, for the desktop to build up completely first:
/bin/bash -c "sleep 15 && python3 /path/to/run_intray.py transmission-gtk"