I'm using I3 and I use WM_ICON_NAME(STRING) to identify my windows.

I'm looking for something similar to this, but with WM_ICON_NAME(STRING). It is possible to achieve this? Thank you.

if test $(wmctrl -l | grep "name of my window" 2>&1 | wc -l) -eq 1; then 
    echo "the window exists"

There are not many tools that use WM_ICON_NAME as it is often assumed to be set to the same as WM_NAME. You can list all the window ids and run xprop on each of them to get a line such as


and then use awk (or similar) to extract the quoted part of this and compare it to the wanted string. Here's a bash function findicon taking one parameter to do this:

    local myname=${1?}
    wmctrl -l |
    while read id rest
    do xprop -id "$id" WM_ICON_NAME
    done |
    awk -F'"' -v myname="$myname" '
        END {exit !found}'

if findicon 'my icon name'
then echo 'found'

You could use xdotool to search existing windows by their class names and titles.

if xdotool search --name "name of my window" > /dev/null; then
    echo "Window found"
    echo "Window not found"

In above code example xdotool command will return exit status 0 and list of found window id's if there are some windows which title contains "name of my window".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.