From fc6a1b22597ea9ed63e27974609fefd72f8e91c9 Mon Sep 17 00:00:00 2001 From: inigoortega Date: Sat, 11 Jan 2020 16:22:56 +0100 Subject: [PATCH] Telegram reply now works super well --- scripts/telegram-reply.sh | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/scripts/telegram-reply.sh b/scripts/telegram-reply.sh index bec43e1..f0f97f9 100644 --- a/scripts/telegram-reply.sh +++ b/scripts/telegram-reply.sh @@ -1,38 +1,39 @@ #!/usr/bin/env sh get_window_id () { - ids="$(dash $TSCRIPTS/get-xprop-from-pid.sh $telegram_id)" + ids=$(dash "$TSCRIPTS/get-xprop-from-pid.sh" "$telegram_id") - ids="$(echo "$ids" | awk '{print $3}')" - correct_id="" + ids=$(echo "$ids" | awk '{print $3}') 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" + correct1=$(xprop -id "$line" | grep 'WM_STATE(WM_STATE):') + correct2=$(xprop -id "$line" | grep 'WM_NAME(STRING) = "Telegram') + [ -n "$correct1" ] && [ -n "$correct2" ] && + [ ${#line} -gt 2 ] && echo "$line" && break done - } +} telegram-desktop -telegram_id="$(pgrep Telegram)" +telegram_id=$(pgrep Telegram) -window_id="$(get_window_id "$telegram_id")" - -iterations=1000 +iterations=10000 i=0 while [ "$i" -lt $iterations ] do - correct="$(xprop -id "$window_id" | grep "window state: Normal")" + window_id=$(get_window_id "$telegram_id") - [ -n "$correct" ] && break || i="$(( $i + 1))" + if [ -n "$window_id" ]; then + correct=$(xprop -id "$window_id" | grep "window state: Normal") + fi + + [ -n "$correct" ] && break || i=$(( $i + 1 )) done if [ "$i" -lt $iterations ]; then - sleep 0.5 + sleep 0.6 xdotool key alt+7 && xdotool key Return fi