BMX Bicycle freestyle
BMX Bicycle freestyle

Friday, May 7, 2010

Solved: Get focused window id on linux

Get ID of currently focused window (window on top) in bash:

b=$(printf '%x\n' $(xdotool getactivewindow))
a=0x0
ab=$a$b
echo $ab

This can be used to check if webbrowser is active to lower p2p bandwith usage automaticaly:

while true
do
sleep 9
b=$(printf '%x\n' $(xdotool getactivewindow))
a=0x0
ab=$a$b
#echo $ab
browserID=$(wmctrl -l | grep "Firefox" | awk '{ print $1 }')
#echo $browserID
if [ "$ab" = "$browserID" ]
then
#echo browser active, shutting down transmisssion
(ps ax | grep -v grep | grep transmission) #check if transmission
if [ "$?" -eq 0 ];
then
b=$(xwininfo -name Transmission | grep Window\ id:\ | awk '{print $4}') #get programs window id
xvkbd -xsendevent -window $b -text "\Cq" #send keystroke to quit program
echo off send to transmission
sleep 60
fi
else
#echo browser not active
(ps ax | grep -v grep | grep transmission) #check if transmission
if [ "$?" -ne 0 ];
then
transmission -m&
fi
fi
echo
done

0 comments:

Post a Comment