Skip to content

Instantly share code, notes, and snippets.

@Hagb
Created August 14, 2023 12:55
Show Gist options
  • Save Hagb/356ac148f0197be730062dd608a11ac4 to your computer and use it in GitHub Desktop.
Save Hagb/356ac148f0197be730062dd608a11ac4 to your computer and use it in GitHub Desktop.
#!/bin/bash
# MIT License
TIMEOUT=500
TYPE_DELAY=100
TH123_CLASSNAME=th123.exe
is_focus() {
[ "x$TH123_CLASSNAME" = "x$(xprop -id "$(xdotool getwindowfocus)" | rg WM_CLASS | cut -d \" -f2)" ]
}
if ! is_focus; then
zenity --error --text "You are not in "$TH123_CLASSNAME""
exit 1
fi
text="$(zenity --entry --text 'Input' --title 'Unicode Input')"
delay=50
delay_total=0
delay_s="$(printf '%.3f' "${delay}e-3")"
while ! is_focus; do
sleep "$delay_s"
((delay_total+=delay))
if ((delay_total>TIMEOUT)) ; then
zenity --error --text ""$TH123_CLASSNAME" getting focus TIMEOUT!"
exit 2
fi
done
xdotool type --delay $TYPE_DELAY -- "$text "
xdotool key --delay $TYPE_DELAY BackSpace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment