51 lines
1.4 KiB
Bash
Executable File
51 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Adapted from the bash snippet found at:
|
|
# https://bbs.archlinux.org/viewtopic.php?id=117031
|
|
|
|
# Get window title, handling Wine virtual desktop child windows
|
|
get_window_title() {
|
|
local exeName="$1"
|
|
local wndFocus wndTitle
|
|
|
|
wndFocus=$(xdotool getwindowfocus)
|
|
wndTitle=$(xprop -id "$wndFocus" WM_NAME 2>/dev/null)
|
|
|
|
# Check if we're focused on Wine Desktop
|
|
if [[ "$wndTitle" == *"Wine Desktop"* ]]; then
|
|
# Look for child window belonging to our executable
|
|
wndTitle=$(xwininfo -tree -root 2>/dev/null | grep -i "\"$exeName\"" | head -1)
|
|
# Extract the window title from xwininfo output (format: 0xID "Title": ("class" "class"))
|
|
if [[ "$wndTitle" =~ \"([^\"]+)\":\ \(\"$exeName\" ]]; then
|
|
echo "${BASH_REMATCH[1]}"
|
|
return
|
|
fi
|
|
fi
|
|
|
|
# Standard case - extract title from xprop output
|
|
if [[ "$wndTitle" =~ \"(.*)\" ]]; then
|
|
echo "${BASH_REMATCH[1]}"
|
|
fi
|
|
}
|
|
|
|
# Wait for the application to start
|
|
while ! pgrep -u "$USER" "^$1" &> /dev/null ; do
|
|
sleep 0.05
|
|
done
|
|
|
|
# Read so long as the application is running
|
|
while pgrep -u "$USER" "^$1" &> /dev/null ; do
|
|
sleep 0.05
|
|
if [[ -f ~/.agmsilent ]]; then
|
|
continue
|
|
fi
|
|
|
|
wndTitle=$(get_window_title "$1")
|
|
|
|
if [[ -n "$wndTitle" ]] && [[ "$oldTitle" != "$wndTitle" ]]; then
|
|
spd-say -- "$wndTitle"
|
|
oldTitle="$wndTitle"
|
|
fi
|
|
done
|
|
|
|
exit 0
|