You are not logged in.
Hi there,
is there a possibility in xfce to catch the event when a window or app switches from foreground to background and vice versa, and then start a script? Reason is I use Virtualbox in seamless mode for a certain program, but don't need it running (consuming lots of CPU power) when switched into the background (=other window topping it). With a script being executed when the window is sent into the background, I could pause the VM, and restart when topped.
Googling "background" only finds tons of "how to run a command in background" topics
Thanks!
Offline
You could xdotool to return the currently focused window and act accordingly:
xdotool getactivewindow getwindowname
...in a script something like this:
#!/bin/bash
while true; do
if ! [[ "$(xdotool getactivewindow getwindowname)" == *"Mousepad" ]]; then
echo "Mousepad is no longer focused"
else
echo "Mousepad is focused"
fi
sleep 1
done
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Kudos! Thank you very much, works like a charm!
My resulting working code, VM window name for VBoxManage command retrieved with
VBoxManage list runningvms
#!/bin/bash
while true; do
activewindow=`xdotool getactivewindow getwindowname` # get full VM window name into variable
echo 0 $activewindow
activewindow7=${activewindow:0:7} # name of VM window changes when paused, so just focus on the important part of name
echo 7 $activewindow7
if ! [[ "$activewindow7" == *"VM_Win7" ]]; then
VBoxManage controlvm "VM_Win7" pause
else
VBoxManage controlvm "VM_Win7" resume
fi
sleep 1
done
Offline
[ Generated in 0.009 seconds, 7 queries executed - Memory usage: 538.8 KiB (Peak: 562.02 KiB) ]