How to open a program and then close its window via CLI?

I am using several programs on my computer that minimize to tray, but do not have an option to start minimized to tray. I have them set to open at the start, and as a result every time I boot up my computer I have to close a bunch of random windows. Needless to say, that is a bit annoying.

Is there a way to create some kind of startup script that will open these programs and then close their windows, without killing the process entirely?

Assuming you have ‘MinimizeAll’ script enabled then the following qdbus string should work.
I’d probably just put it all in one script, and use kstart5 to breakaway the processes … such as:
#!/bin/env bash
kstart5 kate -n &
kstart5 firefox &
qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.invokeShortcut "MinimizeAll" &
return 2> /dev/null; exit

The problem is I would like the windows closed, not minimized. And only specific ones, others I would like open. I kinda have a lot of startup programs lol

Oh sorry I guess I misunderstood this.
So its windows that are closed but not exited the application, icon still exists in task tray in panel.
There is probably another qdbus way of doing it … but all of my tests show it unreliable because it closes whatever open window. I also feel something like pkill would terminate the whole process.

So … unless someone has a better idea … then you could maybe employ xdotool or wmctrl.

Why have them auto start just to close them?

To launch their tray widget.

Then i would suggest to contact the developers of those programs to implement a “start in tray” or similar functionality…

Not sure if the wmctlrl command also terminates the process, but you could try to use:

wmctrl -Fc "Title of the window"



So what you want is not to close them, but to minimize them - if possible to the system tray.

… I don’t know how to do it, never had a need for that -
depends on the program as well.
But if you can do it with a mouse action, it’s also doable via command line usually.

FYI the package has a dead link to the source. The code is available and there is also a pull request with a bunch of improvements, at

More recent fork with the improvements merged: GitHub - kfogel/wmctrl: Unix command-line tool to interact with an EWMH/NetWM-compatible X Window Manager. See home site for upstream information.

I’m not even running Manjaro at present, so no idea about the package used here :woman_shrugging:
It most likely is a bad Arch package i guess…

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.