dotfiles/scripts/telegram-reply.sh

39 lines
852 B
Bash

#!/usr/bin/env sh
get_window_id () {
ids="$(dash $TSCRIPTS/get-xprop-from-pid.sh $telegram_id)"
ids="$(echo "$ids" | awk '{print $3}')"
correct_id=""
echo "$ids" |
while read line
do
correct1="$(xprop -id "$line" | grep "WM_STATE(WM_STATE):")"
correct2="$(xprop -id "$line" | \
grep "WM_NAME(STRING) = \"Telegram\"")"
[ -n "$correct1" -a -n "$correct2" ] && echo "$line"
done
}
telegram-desktop
telegram_id="$(pgrep Telegram)"
window_id="$(get_window_id "$telegram_id")"
iterations=1000
i=0
while [ "$i" -lt $iterations ]
do
correct="$(xprop -id "$window_id" | grep "window state: Normal")"
[ -n "$correct" ] && break || i="$(( $i + 1))"
done
if [ "$i" -lt $iterations ]; then
sleep 0.5
xdotool key alt+7 && xdotool key Return
fi