I am trying to hide and show gmusicbrowser with a custom hotkey, which all together works, however it does not always open "in front" of other applications. So the theory was to use xdotool to sniff out the window and bring it in the front. I've done this in the past with `xdotool search -class "XXX"` however as my gmusic only has the song name in the title bar I cannot search for it. I have tried to check via the pid, but it returns many many windows :D

xdotool search --pid 4785
58720257
58738035
58738262
58738542
58746806
58720424
58831293
58829756
58850763
58720263
58720291

So I think the easiest way would be to include gmusicbrowser in the title bar.

Umm though I didn't need that long and actually not particularly helpful here is the full script (I'm no bash dev :D):

#!/bin/bash

# Get the PID of gmusicbrowser
pid=$(ps ax | grep 'gmusic' | awk '{print $1}' | head -n 1)

if [[ -z "$pid" ]]; then
    echo "gmusicbrowser is not running."
    exit 1
fi

gmusicWindowId=$(xdotool search --pid $pid | tail -n 2 | head -n 1)

if [[ -z "$gmusicWindowId" ]]; then
    echo "No window ID found for gmusicbrowser."
    exit 1
fi

currentWindowPid=$(xdotool getactivewindow getwindowpid)

if [[ "$currentWindowPid" == "$pid" ]]; then
    #/home/hutber/gmusicbrowser-1.1.99.1/gmusicbrowser.pl -cmd Hide
    xdotool windowunmap `echo $gmusicWindowId`
else
    xdotool windowmap `echo  $gmusicWindowId` && xdotool windowactivate $gmusicWindowId && xdotool windowfocus $gmusicWindowId
fi