How do i query and activate a windows in shell?

My use case is kinda niche. I want to write a script that activates a window when I hit a shortcut. The script should activate a program if an instance of it is running.

For example: I start a firefox instance manually. If I minimize it and hit alt+F, firefox should be unminimized and/or maximized.

The GNOME equivalent that I’ve been using is this:

// $APP_NAME in this case example is "firefox"
if xdotool search --name "$APP_NAME" > /dev/null 2>&1; then

    echo "found it"
    wmctrl -a "$APP_NAME"
    wmctrl -r "$APP_NAME" -b add,maximized_vert,maximized_horz

wmctrl and xdotool are as far as I know not fully compatible with KDE.
I use Fedora Linux 42, KDE Plasma edition

Have you explored kdotool ? (It’s in the Fedora repos so you can sudo dnf install kdotool .)

Thanks bro i love you

1 Like

would you know a way to maximize a window?
I got the activation part finished, but kdotool does not have MAXIMIZED_VERT and MAXIMIZED_HORZ

Good question. I just hardcode my screen size (obviously not very good for a portable script).

The dev says on the README that MAXIMIZED_VERT and MAXIMIZED_HORZ are currently missing, but it’s not very clear when they will be added.