Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bash script to remove highlight from yad form date filed
#!/bin/bash
# check if xdotool is installed
if ! hash xdotool; then
echo "Install xdotool!"
exit 1
fi
TEMPFILE="$(mktemp /tmp/yadformX.XXXXXX)"
# Trap that removes temporary file on exit
trap "rm -f $TEMPFILE" EXIT
# Class is necesary here
printf "%s\n" "12/05/18" "4:40" | yad --class "lilyad" --form --field="Date:DT" --field="Date" --cycle-read >>$TEMPFILE & YADFPID=$!
# Sleep untill main window opens, that is until window name appears
until xdotool getwindowname "$(xdotool search --any --class "lilyad" 2>/dev/null | tail -1 2>/dev/null)" &>/dev/null; do
# sleep until the window opens
sleep .1
done
# Decimal window id
WindowID="$(xdotool search --any --class "lilyad" 2>/dev/null | tail -1)"
# Base seven
WindowIDbSeven=$(printf "0x%07x" ${WindowID})
xprop -root -spy _NET_ACTIVE_WINDOW | # <- this is the watcher process
while IFS=$'#' read -a WIN; do
WIN="${WIN[1]%%","*}"
WIN="$(printf "%s\n" ${WIN})" # bypass weird array bug
if [[ "${WIN}" == "${WindowIDbSeven}" ]]; then
xdotool key --clearmodifiers "$WindowIDbSeven" ctrl+Right # send ctrl+Right to de-highlight
fi
WIN=()
done & WATCH_PID=$!
wait $YADFPID
YADEXITST=$? # yad form return status
kill $WATCH_PID
echo "Results:"
cat $TEMPFILE
echo "yad form exit status: $YADEXITST"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment