Tuesday, November 10, 2015

Mapping PID to Window ID / For Focusing and More!

CMD_PID=${1} && while IFS= read -r -d '' var; do 
if grep -q "^WINDOWID=" <<< "$var"; then 
 winid=$(printf '0x%x\n' $(sed 's/WINDOWID=//' <<< "${var}"))
 child_cnt=0 && IFS=$(echo -en "\n\b") && 
for a in $(xwininfo -root -tree | tac | sed -n "/${winid}/,\$p"); do grep -q -i "children" <<< "${a}" && let child_cnt+=1 ((${child_cnt} == 2)) && real_winid=$(grep -o '0x[^ ]*' <<< "${last_line}") && break last_line="${a}" done xdotool windowraise ${real_winid} break fi done < /proc/${CMD_PID}/environ

No comments:

Post a Comment