Umm though I didn't need that long and actually not particularly helpful here is the full script (I'm no bash dev :D):
Code Select
#!/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